From a76e853dfcfbf87b4ddc201efed08b7bb98e8c44 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 1 Feb 2017 14:09:12 +0100 Subject: [PATCH] Try to recreate CanBookBeRenewed perf issue https://bugs.koha-community.org/show_bug.cgi?id=17941 --- test.pl | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test.pl diff --git a/test.pl b/test.pl new file mode 100644 index 0000000..b2be4c6 --- /dev/null +++ b/test.pl @@ -0,0 +1,51 @@ +use C4::Context; +use C4::Items; +use C4::Members; +use Koha::Patron::Categories; +use Koha::Biblios; +use Koha::Libraries; +my $biblio = Koha::Biblios->search->next; +my $library = Koha::Libraries->search->next; +my $patron_category = Koha::Patron::Categories->next; +my $patron = Koha::Patrons->next; +C4::Context->_new_userenv('DUMMY SESSION'); +C4::Context->set_userenv( 0, 0, 0, 'firstname', 'surname', + $library->{branchcode}, + 'Library 1', 0, '', '' ); +C4::Context->set_preference( 'AllowRenewalIfOtherItemsAvailable', 1 ); + +my ( @itemnumbers, @borrowernumbers ); +for my $i ( 1 .. 20 ) { + warn "Adding item $i"; + my ( undef, undef, $itemnumber ) = C4::Items::AddItem( + { + homebranch => $library->branchcode, + holdingbranch => $library->branchcode, + barcode => "barcode_$i" + }, + $biblio->biblionumber + ); + push @itemnumbers, $itemnumber; +} + +for my $i ( 1 .. 201 ) { + warn "Adding patron $i"; + my ( $borrowernumber, undef ) = C4::Members::AddMember( + categorycode => $patron_category->categorycode, + branchcode => $library->branchcode + ); + push @borrowernumbers, $borrowernumber; +} + +C4::Circulation::AddIssue( $patron->unblessed, "barcode_1" ); +for my $i ( 1 .. 200 ) { + warn "Adding hold $i"; + my $patron = Koha::Patrons->find( $borrowernumbers[ $i - 1 ] ); + my $itemnumber = $itemnumbers[ $i % 19 + 1 ]; + C4::Reserves::AddReserve( $library->branchcode, $patron->unblessed, + $biblio->biblionumber, undef, undef, undef, undef, undef, undef, + $itemnumber ); +} + +#my $checkout = Koha::Checkouts->search({ borrowernumber => $patron->borrowernumber })->next; +#C4::Circulation::CanBookBeRenewed({ $patron->borrowernumber, $checkout->itemnumber }); -- 2.9.3