From 0cada7a323db7f9871b67a07e3343642543b64e0 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Wed, 11 Dec 2013 14:28:53 +0200 Subject: [PATCH] Bug 11369: fix issue that can cause staff client searches to stop working 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 Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer Signed-off-by: Galen Charlton --- catalogue/search.pl | 11 +++++++++-- koha-tmpl/intranet-tmpl/js/browser.js | 13 +++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/catalogue/search.pl b/catalogue/search.pl index b3419be535..55d0abf785 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -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; diff --git a/koha-tmpl/intranet-tmpl/js/browser.js b/koha-tmpl/intranet-tmpl/js/browser.js index c3c151653a..c203d3e24f 100644 --- a/koha-tmpl/intranet-tmpl/js/browser.js +++ b/koha-tmpl/intranet-tmpl/js/browser.js @@ -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 () { -- 2.39.5