Bug 22813 - searchResults queries the Koha::Patron object inside two nested loops
Summary: searchResults queries the Koha::Patron object inside two nested loops
Status: RESOLVED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: master
Hardware: All All
: P5 - low normal (vote)
Assignee: Tomás Cohen Arazi
QA Contact: Martin Renvoize
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-30 15:22 UTC by Tomás Cohen Arazi
Modified: 2019-10-14 20:02 UTC (History)
5 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Who signed the patch off:
Text to go in the release notes:
Version(s) released in:
19.05.00, 18.11.06


Attachments
Bug 22813: remove repetitive queries inside two nested loops in searchResults (2.28 KB, patch)
2019-04-30 15:36 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 22813: remove repetitive queries inside two nested loops in searchResults (2.33 KB, patch)
2019-04-30 18:02 UTC, Liz Rea
Details | Diff | Splinter Review
Bug 22813: (follow-up) Add missing condition (1.81 KB, patch)
2019-04-30 18:49 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 22813: remove repetitive queries inside two nested loops in searchResults (2.39 KB, patch)
2019-05-02 10:58 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 22813: (follow-up) Add missing condition (1.87 KB, patch)
2019-05-02 10:58 UTC, Martin Renvoize
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Tomás Cohen Arazi 2019-04-30 15:22:04 UTC
I haven't benchmarked this, but it seems really bad and easy to fix.

To verify:
Go to C4::Search:2119, notice the IF includes a query for a Koha::Patron object, and then for its related Koha::Patron::Category object. This is done for each item, on each record in the resultset WTF
Comment 1 Tomás Cohen Arazi 2019-04-30 15:36:11 UTC
Created attachment 89137 [details] [review]
Bug 22813: remove repetitive queries inside two nested loops in searchResults

This patch moves a query on Koha::Patrons and then the related
Koha::Patron::Category that needlessly happens inside two nested loops
(all items of all MARC records in the resultset).

The Koha::Patron and Koha::Patron::Category are always the same as it is
fetched from C4::Context->userenv each time.

To test:
- Run:
  $ kshell
 k$ prove t/db_dependent/Search.t
=> SUCCESS: Tests pass
- Apply this patch
- Run:
 k$ prove t/db_dependent/Search.t
=> SUCCESS: Tests still pass!
- Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 2 Liz Rea 2019-04-30 18:02:53 UTC
Created attachment 89150 [details] [review]
Bug 22813: remove repetitive queries inside two nested loops in searchResults

This patch moves a query on Koha::Patrons and then the related
Koha::Patron::Category that needlessly happens inside two nested loops
(all items of all MARC records in the resultset).

The Koha::Patron and Koha::Patron::Category are always the same as it is
fetched from C4::Context->userenv each time.

To test:
- Run:
  $ kshell
 k$ prove t/db_dependent/Search.t
=> SUCCESS: Tests pass
- Apply this patch
- Run:
 k$ prove t/db_dependent/Search.t
=> SUCCESS: Tests still pass!
- Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Comment 3 Tomás Cohen Arazi 2019-04-30 18:49:37 UTC
Created attachment 89151 [details] [review]
Bug 22813: (follow-up) Add missing condition

This patch restores a missing condition. $patron gets renamed to make
it obvious that it related to the logged in user.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 4 Martin Renvoize 2019-05-02 10:58:27 UTC
Created attachment 89220 [details] [review]
Bug 22813: remove repetitive queries inside two nested loops in searchResults

This patch moves a query on Koha::Patrons and then the related
Koha::Patron::Category that needlessly happens inside two nested loops
(all items of all MARC records in the resultset).

The Koha::Patron and Koha::Patron::Category are always the same as it is
fetched from C4::Context->userenv each time.

To test:
- Run:
  $ kshell
 k$ prove t/db_dependent/Search.t
=> SUCCESS: Tests pass
- Apply this patch
- Run:
 k$ prove t/db_dependent/Search.t
=> SUCCESS: Tests still pass!
- Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 5 Martin Renvoize 2019-05-02 10:58:30 UTC
Created attachment 89221 [details] [review]
Bug 22813: (follow-up) Add missing condition

This patch restores a missing condition. $patron gets renamed to make
it obvious that it related to the logged in user.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 6 Martin Renvoize 2019-05-02 10:59:14 UTC
Well spotted!

Passing QA
Comment 7 Nick Clemens 2019-05-07 12:03:02 UTC
Awesome work all!

Pushed to master for 19.05
Comment 8 Martin Renvoize 2019-05-08 15:36:59 UTC
Pushed to 18.11.x for 18.11.06
Comment 9 Lucas Gass 2019-05-30 13:52:07 UTC
backported to 18.05.x for 18.05.13