Bug 39967 - When LoadSearchHistoryToTheFirstLoggedUser is enabled, search history is added at every page load
Summary: When LoadSearchHistoryToTheFirstLoggedUser is enabled, search history is adde...
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: OPAC (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Julian Maurice
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-05-22 09:42 UTC by Julian Maurice
Modified: 2025-05-22 15:24 UTC (History)
1 user (show)

See Also:
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 (1.44 KB, patch)
2025-05-22 10:02 UTC, Julian Maurice
Details | Diff | Splinter Review
Bug 39967: Reload session after modification (1.49 KB, patch)
2025-05-22 15:19 UTC, David Nind
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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.