Bugzilla – Attachment 160262 Details for
Bug 35641
Reduce DB calls when performing inventory on a list of barcodes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35641: Reduce DB lookups when sending a list of barcodes to inventory
Bug-35641-Reduce-DB-lookups-when-sending-a-list-of.patch (text/plain), 4.90 KB, created by
ByWater Sandboxes
on 2023-12-22 17:02:12 UTC
(
hide
)
Description:
Bug 35641: Reduce DB lookups when sending a list of barcodes to inventory
Filename:
MIME Type:
Creator:
ByWater Sandboxes
Created:
2023-12-22 17:02:12 UTC
Size:
4.90 KB
patch
obsolete
>From de34d9b094bc62e9b975672e5f5734b61182681a Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Fri, 22 Dec 2023 13:35:06 +0000 >Subject: [PATCH] Bug 35641: Reduce DB lookups when sending a list of barcodes > to inventory > >This patch does three things: >1 - Removes a specific query for withdrawn status of each item scanned - we can use the withdrawn field >2 - Removes a specific query for checkouts on each item scanned - we can use the onloan field > a - additionally we don't need to fetch the checkout as we check it in to the homebranch, > this is likely incorrect - we should use the current branch, but I preserve behavior for now >3 - Fetches the items ahead of time and builds a hash based on barcode, reduces DB lookups, may raise memory usage > >To test: >1 - Checkout some items >2 - Withdraw some items >3 - Generate a lsit of barcodes including some checked out items and some withdrawn items >4 - Enter that list of barcodes into inventory tool >5 - Note your results >6 - Apply patch >7 - Issue the items again >8 - Repeat inventory >9 - Confirm results are the same as before patch > >Signed-off-by: Andrew Fuerste-Henry <andrewfh@dubcolib.org> >--- > tools/inventory.pl | 52 +++++++++++++++++++++------------------------- > 1 file changed, 24 insertions(+), 28 deletions(-) > >diff --git a/tools/inventory.pl b/tools/inventory.pl >index 65f261feb7..a76beb6be4 100755 >--- a/tools/inventory.pl >+++ b/tools/inventory.pl >@@ -167,11 +167,6 @@ if ( ($uploadbarcodes && length($uploadbarcodes) > 0) || ($barcodelist && length > my $date = $input->param('setdate'); > my $date_dt = dt_from_string($date); > >- my $strsth = "select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =?"; >- my $qonloan = $dbh->prepare($strsth); >- $strsth="select * from items where items.barcode =? and items.withdrawn = 1"; >- my $qwithdrawn = $dbh->prepare($strsth); >- > my @barcodes; > my @uploadedbarcodes; > >@@ -218,33 +213,34 @@ if ( ($uploadbarcodes && length($uploadbarcodes) > 0) || ($barcodelist && length > $template->param( err_length => $err_length, > err_data => $err_data ); > } >+ my @items = Koha::Items->search( { barcode => { -in => \@barcodes } } )->as_list; >+ my %items = map { $_->barcode => $_ } @items; > foreach my $barcode (@barcodes) { >- if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) { >- push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 }; >- } else { >- my $item = Koha::Items->find({barcode => $barcode}); >- if ( $item ) { >- # Modify date last seen for scanned items, remove lost status >- $item->set({ itemlost => 0, datelastseen => $date_dt })->store; >- my $item_unblessed = $item->unblessed; >- $moddatecount++; >- unless ( $dont_checkin ) { >- $qonloan->execute($barcode); >- if ($qonloan->rows){ >- my $data = $qonloan->fetchrow_hashref; >- my ($doreturn, $messages, $iteminformation, $borrower) =AddReturn($barcode, $data->{homebranch}); >- if( $doreturn ) { >- $item_unblessed->{onloan} = undef; >- $item_unblessed->{datelastseen} = dt_from_string; >- } else { >- push @errorloop, { barcode => $barcode, ERR_ONLOAN_NOT_RET => 1 }; >- } >+ my $item = $items{ $barcode }; >+ if ( $item ) { >+ if ( $item->withdrawn ) { >+ push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 }; >+ next; >+ } >+ # Modify date last seen for scanned items, remove lost status >+ $item->set({ itemlost => 0, datelastseen => $date_dt })->store; >+ my $item_unblessed = $item->unblessed; >+ $moddatecount++; >+ unless ( $dont_checkin ) { >+ if ( $item->onloan ){ >+ #FIXME Is this correct? Shouldn't the item be checked in at the branch we are signed in at? >+ my ($doreturn, $messages, $iteminformation, $borrower) =AddReturn($barcode, $item->homebranch); >+ if( $doreturn ) { >+ $item_unblessed->{onloan} = undef; >+ $item_unblessed->{datelastseen} = dt_from_string; >+ } else { >+ push @errorloop, { barcode => $barcode, ERR_ONLOAN_NOT_RET => 1 }; > } > } >- push @scanned_items, $item_unblessed; >- } else { >- push @errorloop, { barcode => $barcode, ERR_BARCODE => 1 }; > } >+ push @scanned_items, $item_unblessed; >+ } else { >+ push @errorloop, { barcode => $barcode, ERR_BARCODE => 1 }; > } > } > $template->param( date => $date ); >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 35641
:
160241
|
160262
|
160983