Skip to content

Commit

Permalink
MONTGOMERY - Bug 28974: Add pagination to holds queue viewer
Browse files Browse the repository at this point in the history
We have a partner processing thousands of holds per day, per branch. At this number of holds, the script loads very slow if it manages to load at all.

Paginating the results of the holds queue will allow this page more flexible and load more quickly.

Test Plan
1) Generate a lot of holds in the holds queue
2) Apply this patch
3) Try out the new pagination bar
4) Ensure the limit and page features function correctly

Signed-off-by: Emmi Takkinen <[email protected]>
  • Loading branch information
kylemhall committed Oct 25, 2024
1 parent 4d411f1 commit a63df1c
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 29 deletions.
39 changes: 28 additions & 11 deletions C4/HoldsQueue.pm
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ Returns hold queue for a holding branch. If branch is omitted, then whole queue

sub GetHoldsQueueItems {
my $params = shift;
my $dbh = C4::Context->dbh;
my $dbh = C4::Context->dbh;

my $search_params;
$search_params->{'me.holdingbranch'} = $params->{branchlimit} if $params->{branchlimit};
$search_params->{'itype'} = $params->{itemtypeslimit} if $params->{itemtypeslimit};
$search_params->{'ccode'} = $params->{ccodeslimit} if $params->{ccodeslimit};
$search_params->{'location'} = $params->{locationslimit} if $params->{locationslimit};
$search_params->{'me.holdingbranch'} = $params->{branchlimit} if $params->{branchlimit};
$search_params->{'itype'} = $params->{itemtypeslimit} if $params->{itemtypeslimit};
$search_params->{'ccode'} = $params->{ccodeslimit} if $params->{ccodeslimit};
$search_params->{'location'} = $params->{locationslimit} if $params->{locationslimit};
my $rows = $params->{limit} || 20;
my $page = $params->{page} || 1;

my $results = Koha::Hold::HoldsQueueItems->search(
$search_params,
Expand All @@ -143,20 +145,35 @@ sub GetHoldsQueueItems {
prefetch => [
'biblio',
'biblioitem',
{
'item' => {
'item_group_item' => 'item_group'
}
}
{ 'item' => { 'item_group_item' => 'item_group' } }
],
order_by => [
'ccode', 'location', 'item.cn_sort', 'author',
'biblio.title', 'pickbranch', 'reservedate'
],
rows => $rows,
page => $page
}
);
my $total_results = Koha::Hold::HoldsQueueItems->search(
$search_params,
{
join => [
'borrower',
],
prefetch => [
'biblio',
'biblioitem',
{ 'item' => { 'item_group_item' => 'item_group' } }
],
order_by => [
'ccode', 'location', 'item.cn_sort', 'author',
'biblio.title', 'pickbranch', 'reservedate'
],
}
)->count;

return $results;
return ( $results, $total_results );
}

=head2 CreateQueue
Expand Down
29 changes: 24 additions & 5 deletions circ/view_holdsqueue.pl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ =head1 view_holdsqueue
use Modern::Perl;
use CGI qw ( -utf8 );
use C4::Auth qw( get_template_and_user );
use C4::Output qw( output_html_with_http_headers );
use C4::Output qw( output_html_with_http_headers pagination_bar );
use C4::HoldsQueue qw( GetHoldsQueueItems );
use Koha::BiblioFrameworks;
use Koha::ItemTypes;
Expand All @@ -44,27 +44,46 @@ =head1 view_holdsqueue
my $run_report = $params->{'run_report'};
my $branchlimit = $params->{'branchlimit'};
my $itemtypeslimit = $params->{'itemtypeslimit'};
my $ccodeslimit = $params->{'ccodeslimit'};
my $ccodeslimit = $params->{'ccodeslimit'};
my $locationslimit = $params->{'locationslimit'};
my $limit = $params->{'limit'} || 20;
my $page = $params->{'page'} || 1;

if ($run_report) {
my $items = GetHoldsQueueItems(
my ( $items, $total ) = GetHoldsQueueItems(
{
branchlimit => $branchlimit,
itemtypeslimit => $itemtypeslimit,
ccodeslimit => $ccodeslimit,
locationslimit => $locationslimit
locationslimit => $locationslimit,
limit => $limit,
page => $page,
}
);

my $pages = int( $total / $limit ) + ( ( $total % $limit ) > 0 ? 1 : 0 );
$template->param(
branchlimit => $branchlimit,
itemtypeslimit => $itemtypeslimit,
ccodeslimit => $ccodeslimit,
locationslimit => $locationslimit,
total => $items->count,
total => $total,
itemsloop => $items,
run_report => $run_report,
page => $page,
limit => $limit,
pagination_bar => pagination_bar(
'view_holdsqueue.pl',
$pages, $page, 'page',
{
branchlimit => $branchlimit,
itemtypeslimit => $itemtypeslimit,
ccodeslimit => $ccodeslimit,
locationslimit => $locationslimit,
limit => $limit,
run_report => 1,
}
),
);
}

Expand Down
27 changes: 27 additions & 0 deletions koha-tmpl/intranet-tmpl/prog/en/modules/circ/view_holdsqueue.tt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,29 @@
[% IF ( ccodeslimit ) %] <span>and collection: [% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.ccode' authorised_value = ccodeslimit ) | html %]</span>[% END %]
[% IF ( locationslimit ) %] <span>and shelving location: [% AuthorisedValues.GetDescriptionByKohaField( kohafield => 'items.location' authorised_value = locationslimit ) | html %]</span>[% END %]
</div>

<form action="view_holdsqueue.pl" method="get" id="limitselect">
<input type="hidden" name="page" value="1"/>
<input type="hidden" name="branchlimit" value="[% branchlimit | html %]"/>
<input type="hidden" name="itemtypeslimit" value="[% itemtypeslimit | html %]"/>
<input type="hidden" name="ccodeslimit" value="[% ccodeslimit | html %]"/>
<input type="hidden" name="locationslimit" value="[% locationslimit | html %]"/>
<input type="hidden" name="run_report" value="1"/>

<label for="limit">Rows per page: </label>
<select name="limit" id="limit">
[% limits = [ 10, 20, 50, 100, 200, 300, 400, 500, 1000 ] %]
[% FOREACH l IN limits %]
[% IF l == limit %]
<option value="[% l | html %]" selected="selected">[% l | html %]</option>
[% ELSE %]
<option value="[% l | html %]">[% l | html %]</option>
[% END %]
[% END %]
</select>
</form> <!-- /#limitselect -->
<div class="pages">[% pagination_bar | $raw %]</div>

[% ELSE %]
<div class="dialog message">No items found.</div>
[% END %]
Expand Down Expand Up @@ -303,6 +326,10 @@
$(document).ready(function() {
var holdst;

$('#limit').change(function() {
$('#limitselect').submit();
});

// Setup filters before DataTables initialisation, in case some columns are
// hidden by default
var filterColumnTimeoutId;
Expand Down
36 changes: 23 additions & 13 deletions t/db_dependent/HoldsQueue.t
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ $dbh->do("DELETE FROM items WHERE holdingbranch = '$borrower_branchcode'");
# Frst branch from StaticHoldsQueueWeight
test_queue ('take from lowest cost branch', 0, $borrower_branchcode, $other_branches[0]);
test_queue ('take from lowest cost branch', 1, $borrower_branchcode, $least_cost_branch_code);
my $queue = C4::HoldsQueue::GetHoldsQueueItems({ branchlimit => $least_cost_branch_code}) || [];
my ( $queue, undef ) = C4::HoldsQueue::GetHoldsQueueItems( { branchlimit => $least_cost_branch_code } );
my $queue_item = $queue->next;
ok( $queue_item
&& $queue_item->pickbranch eq $borrower_branchcode
Expand Down Expand Up @@ -1889,7 +1889,7 @@ subtest 'Remove holds on check-in match' => sub {
};

subtest "GetHoldsQueueItems" => sub {
plan tests => 4;
plan tests => 8;

$schema->storage->txn_begin;

Expand Down Expand Up @@ -1943,27 +1943,37 @@ subtest "GetHoldsQueueItems" => sub {
($itemnumber_3,$biblionumber_3,'','','',42,'','')
" );

my $queue_items = GetHoldsQueueItems();
my ( $queue_items, $queue_count ) = GetHoldsQueueItems();
is( $queue_items->count, $count + 3, 'Three items added to queue' );
is( $queue_count, $count + 3, 'Correct count of items in queue' );

$queue_items = GetHoldsQueueItems( { itemtypeslimit => $item_1->itype } );
is( $queue_items->count,
3, 'Three items of same itemtype found when itemtypeslimit passed' );
( $queue_items, $queue_count ) = GetHoldsQueueItems( { itemtypeslimit => $item_1->itype } );
is(
$queue_items->count,
3, 'Three items of same itemtype found when itemtypeslimit passed'
);
is( $queue_count, $count + 3, 'Correct count of items in queue' );

$queue_items = GetHoldsQueueItems(
{ itemtypeslimit => $item_1->itype, ccodeslimit => $item_2->ccode } );
is( $queue_items->count,
2, 'Two items of same collection found when ccodeslimit passed' );
( $queue_items, $queue_count ) =
GetHoldsQueueItems( { itemtypeslimit => $item_1->itype, ccodeslimit => $item_2->ccode } );
is(
$queue_items->count,
2, 'Two items of same collection found when ccodeslimit passed'
);
is( $queue_count, $count + 2, 'Correct count of items in queue' );

$queue_items = GetHoldsQueueItems(
( $queue_items, $queue_count ) = GetHoldsQueueItems(
{
itemtypeslimit => $item_1->itype,
ccodeslimit => $item_2->ccode,
locationslimit => $item_3->location
}
);
is( scalar $queue_items->count,
1, 'One item of shleving location found when locationslimit passed' );
is(
scalar $queue_items->count,
1, 'One item of shelving location found when locationslimit passed'
);
is( $queue_count, $count + 1, 'Correct count of items in queue' );

$schema->storage->txn_rollback;
};
Expand Down

0 comments on commit a63df1c

Please sign in to comment.