Bug 11369: fix issue that can cause staff client searches to stop working
authorOlli-Antti Kivilahti <olli-antti.kivilahti@jns.fi>
Wed, 11 Dec 2013 12:28:53 +0000 (14:28 +0200)
committerGalen Charlton <gmc@esilibrary.com>
Fri, 2 May 2014 23:17:04 +0000 (23:17 +0000)
This patch fixes an issue where too many search cursor cookies overflow
the HTTP-header size after making multiple searches in the staff client.

To replicate this issue, make multiple searches in catalogue/search.pl.
50+ Should be enough to cause the HTTP-request header to overgrow.
One can verify this issue by observing the searchCookie growth in
browser's stored cookies.

-------------
- TEST PLAN -
-------------

Keep making searches.
One should never have more than 10 searchCookies. Browser might display
only 9, because for some reason the newest js-generated cookie is not
included in Firefox's cookies listing.

------------
- DRAWBACK -
------------

Removing these cookies disables the search cursor for traversing search
results (next/previous) for the removed cookie. This maybe be problematic
in some cases,
(for ex when multiple search tabs need to be open and they need to be
 traversed)
One easy solution is to grow the amount of stored searchCookies from 10 to
20, but 10 is chosen so there will be plenty of room for other cookies as
well.

Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
catalogue/search.pl
koha-tmpl/intranet-tmpl/js/browser.js

index b3419be..55d0abf 100755 (executable)
@@ -678,8 +678,15 @@ for (my $i=0;$i<@servers;$i++) {
 } #/end of the for loop
 #$template->param(FEDERATED_RESULTS => \@results_array);
 
-$template->{'VARS'}->{'searchid'} = $cgi->param('searchid')
-  || String::Random::random_string('ssssssss');
+if ($cgi->param('searchid')) {
+       $template->{'VARS'}->{'searchid'} = $cgi->param('searchid');
+}
+else {
+  my $dt = DateTime->now(time_zone  => 'local');
+ #We are generating a clean numeric datetime representation so we can easily compare them using the default javascript lexigraphic sorter.
+      $template->{'VARS'}->{'searchid'} = 'scs_'.$dt->ymd('').$dt->hms(''); #scs == Staff Client
+}
+
 my $gotonumber = $cgi->param('gotoNumber');
 if ($gotonumber eq 'last' || $gotonumber eq 'first') {
     $template->{'VARS'}->{'gotoNumber'} = $gotonumber;
index c3c1516..c203d3e 100644 (file)
@@ -40,6 +40,19 @@ KOHA.browser = function (searchid, biblionumber) {
                 pagelen: newresults.length,
                 results: newresults
             };
+
+            //Bug_11369 Cleaning up excess searchCookies to prevent cookie overflow in the browser memory.
+            var allVisibleCookieKeys = Object.keys( $.cookie() );
+            var scsCookieKeys = $.grep( allVisibleCookieKeys,
+                function(elementOfArray, indexInArray) {
+                    return ( elementOfArray.search(/^scs_\d/) != -1 ); //We are looking for specifically staff client searchCookies.
+                }
+            );
+            if (scsCookieKeys.length >= 10) {
+                scsCookieKeys.sort(); //Make sure they are in order, oldest first!
+                $.removeCookie( scsCookieKeys[0], { path: '/' } );
+            }
+            //EO Bug_11369
         }
         $.cookie(me.searchid, JSON.stringify(me.searchCookie), { path: '/' });
         $(document).ready(function () {