[Bast-commits] r6529 - in DBIx-Class/0.08/trunk: lib/DBIx/Class/Storage t/multi_create

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Sat Jun 6 08:47:47 GMT 2009


Author: ribasushi
Date: 2009-06-06 08:47:47 +0000 (Sat, 06 Jun 2009)
New Revision: 6529

Added:
   DBIx-Class/0.08/trunk/t/multi_create/reentrance_count.t
Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/Statistics.pm
Log:
TODOified reentrancy counter - this shall be used to optimize MC some day

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/Statistics.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/Statistics.pm	2009-06-06 08:45:10 UTC (rev 6528)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/Statistics.pm	2009-06-06 08:47:47 UTC (rev 6529)
@@ -89,6 +89,8 @@
 sub txn_begin {
   my $self = shift;
 
+  return if $self->callback;
+
   $self->print("BEGIN WORK\n");
 }
 
@@ -100,6 +102,8 @@
 sub txn_rollback {
   my $self = shift;
 
+  return if $self->callback;
+
   $self->print("ROLLBACK\n");
 }
 
@@ -111,6 +115,8 @@
 sub txn_commit {
   my $self = shift;
 
+  return if $self->callback;
+
   $self->print("COMMIT\n");
 }
 
@@ -122,6 +128,8 @@
 sub svp_begin {
   my ($self, $name) = @_;
 
+  return if $self->callback;
+
   $self->print("SAVEPOINT $name\n");
 }
 
@@ -133,7 +141,9 @@
 sub svp_release {
   my ($self, $name) = @_;
 
- $self->print("RELEASE SAVEPOINT $name\n");
+  return if $self->callback;
+
+  $self->print("RELEASE SAVEPOINT $name\n");
 }
 
 =head2 svp_rollback
@@ -144,7 +154,9 @@
 sub svp_rollback {
   my ($self, $name) = @_;
 
- $self->print("ROLLBACK TO SAVEPOINT $name\n");
+  return if $self->callback;
+
+  $self->print("ROLLBACK TO SAVEPOINT $name\n");
 }
 
 =head2 query_start

Added: DBIx-Class/0.08/trunk/t/multi_create/reentrance_count.t
===================================================================
--- DBIx-Class/0.08/trunk/t/multi_create/reentrance_count.t	                        (rev 0)
+++ DBIx-Class/0.08/trunk/t/multi_create/reentrance_count.t	2009-06-06 08:47:47 UTC (rev 6529)
@@ -0,0 +1,180 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Exception;
+use lib qw(t/lib);
+use DBICTest;
+
+plan 'no_plan';
+
+my $schema = DBICTest->init_schema();
+
+my $query_stats;
+$schema->storage->debugcb (sub { push @{$query_stats->{$_[0]}}, $_[1] });
+$schema->storage->debug (1);
+
+TODO: {
+  local $TODO = 'This is an optimization task, will wait... a while';
+
+lives_ok (sub {
+  undef $query_stats;
+  $schema->resultset('Artist')->create ({
+    name => 'poor artist',
+    cds => [
+      {
+        title => 'cd1',
+        year => 2001,
+      },
+      {
+        title => 'cd2',
+        year => 2002,
+      },
+    ],
+  });
+
+  is ( @{$query_stats->{INSERT} || []}, 3, 'number of inserts during creation of artist with 2 cds' );
+  is ( @{$query_stats->{SELECT} || []}, 0, 'number of selects during creation of artist with 2 cds' )
+    || $ENV{DBIC_MULTICREATE_DEBUG} && diag join "\n", @{$query_stats->{SELECT} || []};
+});
+
+
+lives_ok (sub {
+  undef $query_stats;
+  $schema->resultset('Artist')->create ({
+    name => 'poorer artist',
+    cds => [
+      {
+        title => 'cd3',
+        year => 2003,
+        genre => { name => 'vague genre' },
+      },
+      {
+        title => 'cd4',
+        year => 2004,
+        genre => { name => 'vague genre' },
+      },
+    ],
+  });
+
+  is ( @{$query_stats->{INSERT} || []}, 4, 'number of inserts during creation of artist with 2 cds, converging on the same genre' );
+  is ( @{$query_stats->{SELECT} || []}, 0, 'number of selects during creation of artist with 2 cds, converging on the same genre' )
+    || $ENV{DBIC_MULTICREATE_DEBUG} && diag join "\n", @{$query_stats->{SELECT} || []};
+});
+
+
+lives_ok (sub {
+  my $genre = $schema->resultset('Genre')->first;
+  undef $query_stats;
+  $schema->resultset('Artist')->create ({
+    name => 'poorest artist',
+    cds => [
+      {
+        title => 'cd5',
+        year => 2005,
+        genre => $genre,
+      },
+      {
+        title => 'cd6',
+        year => 2004,
+        genre => $genre,
+      },
+    ],
+  });
+
+  is ( @{$query_stats->{INSERT} || []}, 3, 'number of inserts during creation of artist with 2 cds, converging on the same existing genre' );
+  is ( @{$query_stats->{SELECT} || []}, 0, 'number of selects during creation of artist with 2 cds, converging on the same existing genre' )
+    || $ENV{DBIC_MULTICREATE_DEBUG} && diag join "\n", @{$query_stats->{SELECT} || []};
+});
+
+
+lives_ok (sub {
+  undef $query_stats;
+  $schema->resultset('Artist')->create ({
+    name => 'poorer than the poorest artist',
+    cds => [
+      {
+        title => 'cd7',
+        year => 2007,
+        cd_to_producer => [
+          {
+            producer => {
+              name => 'jolly producer',
+              producer_to_cd => [
+                {
+                  cd => {
+                    title => 'cd8',
+                    year => 2008,
+                    artist => {
+                      name => 'poorer than the poorest artist',
+                    },
+                  },
+                },
+              ],
+            },
+          },
+        ],
+      },
+    ],
+  });
+
+  is ( @{$query_stats->{INSERT} || []}, 6, 'number of inserts during creation of artist->cd->producer->cd->same_artist' );
+  is ( @{$query_stats->{SELECT} || []}, 0, 'number of selects during creation of artist->cd->producer->cd->same_artist' )
+    || $ENV{DBIC_MULTICREATE_DEBUG} && diag join "\n", @{$query_stats->{SELECT} || []};
+});
+
+lives_ok (sub {
+  undef $query_stats;
+  $schema->resultset ('Artist')->find(1)->create_related (cds => {
+    title => 'cd9',
+    year => 2009,
+    cd_to_producer => [
+      {
+        producer => {
+          name => 'jolly producer',
+          producer_to_cd => [
+            {
+              cd => {
+                title => 'cd10',
+                year => 2010,
+                artist => {
+                  name => 'poorer than the poorest artist',
+                },
+              },
+            },
+          ],
+        },
+      },
+    ],
+  });
+
+  is ( @{$query_stats->{INSERT} || []}, 4, 'number of inserts during creation of existing_artist->cd->existing_producer->cd->existing_artist2' );
+  is ( @{$query_stats->{SELECT} || []}, 0, 'number of selects during creation of existing_artist->cd->existing_producer->cd->existing_artist2' )
+    || $ENV{DBIC_MULTICREATE_DEBUG} && diag join "\n", @{$query_stats->{SELECT} || []};
+});
+
+lives_ok (sub {
+  undef $query_stats;
+
+  my $artist = $schema->resultset ('Artist')->first;
+  my $producer = $schema->resultset ('Producer')->first;
+
+  $schema->resultset ('CD')->create ({
+    title => 'cd11',
+    year => 2011,
+    artist => $artist,
+    cd_to_producer => [
+      {
+        producer => $producer,
+      },
+    ],
+  });
+
+  is ( @{$query_stats->{INSERT} || []}, 2, 'number of inserts during creation of artist_object->cd->producer_object' );
+  is ( @{$query_stats->{SELECT} || []}, 0, 'number of selects during creation of artist_object->cd->producer_object' )
+    || $ENV{DBIC_MULTICREATE_DEBUG} && diag join "\n", @{$query_stats->{SELECT} || []};
+});
+
+}
+
+1;




More information about the Bast-commits mailing list