Bug 39967

Summary: When LoadSearchHistoryToTheFirstLoggedUser is enabled, search history is added at every page load
Product: Koha Reporter: Julian Maurice <julian.maurice>
Component: OPACAssignee: Julian Maurice <julian.maurice>
Status: Signed Off --- QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: david
Version: Main   
Hardware: All   
OS: All   
GIT URL: Change sponsored?: ---
Patch complexity: --- Documentation contact:
Documentation submission: Text to go in the release notes:
This fixes the search history recorded in the OPAC. The search history--before logging in to the OPAC--was duplicated every time after you log in AND reloaded the search history page (Your account > Search history).
Version(s) released in:
Circulation function:
Attachments: Bug 39967: Reload session after modification
Bug 39967: Reload session after modification

Description Julian Maurice 2025-05-22 09:42:52 UTC
Steps to reproduce:
1. Enable LoadSearchHistoryToTheFirstLoggedUser and EnableOpacSearchHistory 
2. Go to OPAC. If logged in, log out.
3. Go to search history and remove all searches if any.
4. Perform a search, make sure it appears in your search history
5. Log in and go to your search history. See that your unauthenticated search history has been added to your account's search history
6. Reload the page multiple times. See that the unauthenticated search history is re-added after each page reload, making your search history grow every time.
Comment 1 Julian Maurice 2025-05-22 10:02:14 UTC
Created attachment 182724 [details] [review]
Bug 39967: Reload session after modification

Otherwise the existing $session still holds outdated data that is
written on the next flush, which overwrites what has been set by
C4::Search::History::set_to_session

Test plan:
1. Enable LoadSearchHistoryToTheFirstLoggedUser and EnableOpacSearchHistory
2. Go to OPAC. If logged in, log out.
3. Go to search history and remove all searches if any.
4. Perform a search, make sure it appears in your search history
5. Log in and go to your search history. See that your unauthenticated
   search history has been added to your account's search history
6. Reload the page multiple times. See that the unauthenticated search
   history is *NOT* re-added after each page reload
Comment 2 David Nind 2025-05-22 15:19:09 UTC
Created attachment 182738 [details] [review]
Bug 39967: Reload session after modification

Otherwise the existing $session still holds outdated data that is
written on the next flush, which overwrites what has been set by
C4::Search::History::set_to_session

Test plan:
1. Enable LoadSearchHistoryToTheFirstLoggedUser and EnableOpacSearchHistory
2. Go to OPAC. If logged in, log out.
3. Go to search history and remove all searches if any.
4. Perform a search, make sure it appears in your search history
5. Log in and go to your search history. See that your unauthenticated
   search history has been added to your account's search history
6. Reload the page multiple times. See that the unauthenticated search
   history is *NOT* re-added after each page reload

Signed-off-by: David Nind <david@davidnind.com>
Comment 3 David Nind 2025-05-22 15:24:53 UTC
Testing notes (using KTD):

1. The system preferences are already enabled in KTD.

2. Replicate the problem using the steps in the bug description.

3. Apply the patch, reset_all, and run through the steps in the patch to show that it is fixed.