From d44c47ce6483e2da00372d34421ad7d83137e15d Mon Sep 17 00:00:00 2001 From: Andrew Nugged Date: Thu, 21 Nov 2019 16:46:36 +0200 Subject: [PATCH] Bug 24027: (follow-up) Don't combine multiple items add POST page with list generation When hundreds or thousands of items added, it takes time to add to DB. Then generation of items list in the SAME request also takes time. This "doubles" page generation time. This patch proposes to show only the number of added and total items on POST-generated page instead of list generation, but not always: only if some limit are reached ("OpacMaxItemsToDisplay" // 50 is used), and propose navigation link for the user to see the list after. It's much more sensible on big databases and libraries hosting/clouds with limited resources even up to page generation timeout. This stacks up with previous patch for the combined speed up effect. Other improvements with this patch: because added counters for both: - added now items, - overall items for this biblioid in DB, it is now shows: - number of added items after adding in "dialog message" style box, - number of total displayed items on the beginning of the list table. Signed-off-by: Michal Denar --- cataloguing/additem.pl | 49 +++++++++++++++++++++- .../prog/en/modules/cataloguing/additem.tt | 15 +++++++ 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index cb26db28a7..b0c289a2a7 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -397,6 +397,9 @@ my $fa_duedatespec = $input->param('duedatespec'); my $frameworkcode = &GetFrameworkCode($biblionumber); +# counter for multiple added items to put into template +my $num_items_added = 0; + # Defining which userflag is needing according to the framework currently used my $userflags; if (defined $input->param('frameworkcode')) { @@ -517,6 +520,7 @@ if ($op eq "additem") { $cookie = [ $cookie, $itemcookie ]; } + $num_items_added++; } $nextop = "additem"; if ($exist_itemnumber) { @@ -538,7 +542,8 @@ if ($op eq "additem") { $fieldItem->delete_subfields($tagsubfield); $itemrecord->insert_fields_ordered($fieldItem); } - $itemrecord = removeFieldsForPrefill($itemrecord) if ($prefillitem); + $itemrecord = removeFieldsForPrefill($itemrecord) if ($prefillitem); + $num_items_added++; } # If we have to add multiple copies @@ -610,6 +615,8 @@ if ($op eq "additem") { $i++; # Only increment copynumber if item was really added $copynumber++ if ( $copynumber && $copynumber =~ m/^\d+$/ ); + + $num_items_added++; } # Preparing the next iteration @@ -760,6 +767,44 @@ if ($op eq "additem") { # build screen with existing items. and "new" one #------------------------------------------------------------------------------- +my $items_counter = Koha::Items->count( {biblionumber => $biblionumber} ); + +# Don't display if that was additems mode request and too big list limt is reached, +# for not to make POST page load so long because adding items takes time + generation too +my $max_items_to_display_on_add = C4::Context->preference('OpacMaxItemsToDisplay') // 50; +if( $num_items_added > 0 and $items_counter > $max_items_to_display_on_add ) { + # another call of template with empty sets (full call when list generated is down below) + $template->param( + biblionumber => $biblionumber, + title => $oldrecord->{title}, + author => $oldrecord->{author}, + num_items_added => $num_items_added, + items_counter => $items_counter, + dont_display_after_add => 1, + item_loop => \(), + item_header_loop => \(), + item => \(), + itemnumber => $itemnumber, + barcode => undef, + itemtagfield => undef, + itemtagsubfield => undef, + op => $nextop, + popup => scalar $input->param('popup') ? 1 : 0, + C4::Search::enabled_staff_search_views, + ); + $template->{'VARS'}->{'searchid'} = $searchid; + + foreach my $error (@errors) { + $template->param( $error => 1 ); + } + output_html_with_http_headers $input, $cookie, $template->output; + + # we stop here, template is generated + exit; +} + + + # now, build existiing item list my $temp = GetMarcBiblio({ biblionumber => $biblionumber }); #my @fields = $record->fields(); @@ -945,6 +990,8 @@ $template->param( biblionumber => $biblionumber, title => $oldrecord->{title}, author => $oldrecord->{author}, + num_items_added => $num_items_added, + items_counter => $items_counter, item_loop => \@item_value_loop, item_header_loop => \@header_value_loop, item => \@loop_data, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index 641053149c..1c4ce7764e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -42,9 +42,21 @@ [% IF ( not_same_branch ) %]
Cannot delete: The items do not belong to your library.
[% END %] [% IF ( linked_analytics ) %]
Cannot delete: item has linked analytics..
[% END %] +[% IF num_items_added %] +
+

[% num_items_added | html %] item(s) added

+
+[% END %] +[% IF dont_display_after_add %] +
+

Items list is too big ([% items_counter | html %]) to display on post-adding page,

+ Return to the list +
+[% ELSE %]
[% IF ( item_loop ) %]
+

Displaying [% items_counter | html %] items:

@@ -113,6 +125,7 @@
[% END %] +[% END %]
@@ -120,6 +133,7 @@
+[% IF NOT dont_display_after_add %]
@@ -249,6 +263,7 @@
+[% END %]
-- 2.11.0