From faa0046290df362bd1e21957b9c91f191389e93d Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 13 Jul 2017 14:26:21 +0200 Subject: [PATCH] Bug 18937: Limit the number of list entries to print Content-Type: text/plain; charset=utf-8 When you have large lists of say 2000 entries, the option Print a list may be very time consuming. Especially when an impatient user hits refresh a couple of times, this might affect your server performance. This patch adds paging to list printing when the number of list entries is over 200 (just a constant). The number of entries to print is now governed by preference OPACnumSearchResults. Test plan: [1] Pick a small list. Verify that print (add print=1 to URL) includes all records. [2] Pick a large list (>200 entries). Verify that print now only includes records of the current page. --- koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt | 2 +- opac/opac-shelves.pl | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt index 2c162c0..195333c 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -155,7 +155,7 @@ Send list [% END %] - Print list + Print list [% IF can_manage_shelf %] | diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index e790b43..d19622e 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -38,6 +38,8 @@ use Koha::RecordProcessor; use constant ANYONE => 2; +use constant MAX_PRINT_ENTRIES => 200; + my $query = new CGI; my $template_name = $query->param('rss') ? "opac-shelves-rss.tt" : "opac-shelves.tt"; @@ -237,10 +239,13 @@ if ( $op eq 'view' ) { my $direction = $query->param('direction') || 'asc'; $direction = 'asc' if $direction ne 'asc' and $direction ne 'desc'; my ( $page, $rows ); - unless ( $query->param('print') or $query->param('rss') ) { + if ( ( $query->param('print') + && $shelf->get_contents->count > MAX_PRINT_ENTRIES ) + || ( !$query->param('rss') && !$query->param('print') ) ) { $rows = C4::Context->preference('OPACnumSearchResults') || 20; - $page = ( $query->param('page') ? $query->param('page') : 1 ); + $page = $query->param('page') || 1; } + $template->param( page => $page ); my $order_by = $sortfield eq 'itemcallnumber' ? 'items.itemcallnumber' : $sortfield; my $contents = $shelf->get_contents->search( {}, -- 2.1.4