|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
use Modern::Perl; |
| 3 |
use C4::Context; |
| 4 |
use Koha::Database; |
| 5 |
use t::lib::Mocks; |
| 6 |
use Time::HiRes qw(gettimeofday tv_interval); |
| 7 |
|
| 8 |
t::lib::Mocks::mock_preference('item-level_itypes', '1'); |
| 9 |
|
| 10 |
#BEGIN{$ENV{DBIC_TRACE}=1;}; |
| 11 |
|
| 12 |
my $biblionumbers = C4::Context->dbh->selectcol_arrayref(qq{SELECT biblionumber FROM biblio}); |
| 13 |
sub search_unblessed { |
| 14 |
my ($biblionumber) = @_; |
| 15 |
my $items = []; |
| 16 |
my $sth = C4::Context->dbh->prepare(qq{SELECT * FROM items WHERE biblionumber=?}); |
| 17 |
$sth->execute($biblionumber); |
| 18 |
while (my $item = $sth->fetchrow_hashref) { |
| 19 |
push @{$items}, $item; |
| 20 |
} |
| 21 |
return wantarray ? @{$items} : $items; |
| 22 |
} |
| 23 |
sub search_dbic { |
| 24 |
my ($biblionumber) = @_; |
| 25 |
return [Koha::Database->new->schema->resultset('Item')->search( |
| 26 |
{ biblionumber => $biblionumber }, |
| 27 |
{ result_class => 'DBIx::Class::ResultClass::HashRefInflator' } |
| 28 |
)->all |
| 29 |
]; |
| 30 |
} |
| 31 |
|
| 32 |
my ($t0, $elapsed); |
| 33 |
$t0 = [gettimeofday]; |
| 34 |
for my $biblionumber (@$biblionumbers ) { |
| 35 |
search_unblessed($biblionumber); |
| 36 |
} |
| 37 |
$elapsed = tv_interval ( $t0, [gettimeofday]); |
| 38 |
print "plain SQL=${elapsed}s\n"; |
| 39 |
|
| 40 |
$t0 = [gettimeofday]; |
| 41 |
for my $biblionumber (@$biblionumbers ) { |
| 42 |
search_dbic($biblionumber); |
| 43 |
} |
| 44 |
$elapsed = tv_interval ( $t0, [gettimeofday]); |
| 45 |
print "DBIC=${elapsed}s\n"; |