Bug 36350 - Add subclass of Koha::Objects that provides caching for find and search
Summary: Add subclass of Koha::Objects that provides caching for find and search
Status: Needs Signoff
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: David Gustafsson
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-03-18 16:28 UTC by David Gustafsson
Modified: 2024-03-26 17:28 UTC (History)
0 users

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 36350: Add caching for Objects::find (13.90 KB, patch)
2024-03-18 16:32 UTC, David Gustafsson
Details | Diff | Splinter Review
Bug 36350: Add caching for Objects::find (13.95 KB, patch)
2024-03-18 16:46 UTC, David Gustafsson
Details | Diff | Splinter Review
Bug 36350: Add caching for Objects::find and Objects::search (19.42 KB, patch)
2024-03-25 18:50 UTC, David Gustafsson
Details | Diff | Splinter Review
Bug 36350: Add caching for Objects::find and Objects::search (19.44 KB, patch)
2024-03-25 18:52 UTC, David Gustafsson
Details | Diff | Splinter Review
Bug 36350: Add caching for Objects::find and Objects::search (19.25 KB, patch)
2024-03-25 19:16 UTC, David Gustafsson
Details | Diff | Splinter Review
Before (315.49 KB, image/png)
2024-03-25 19:20 UTC, David Gustafsson
Details
After (302.32 KB, image/png)
2024-03-25 19:21 UTC, David Gustafsson
Details
Bug 36350: Add caching for Objects::find and Objects::search (20.28 KB, patch)
2024-03-26 17:26 UTC, David Gustafsson
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description David Gustafsson 2024-03-18 16:28:08 UTC
At our library we have traced some performance issues to repeated find calls for a number of object types. To address this patch introduces a subclass for Koha::Object that if extended instead of the former provides a cached version of find. This patch enables caching for ItemTypes and Libraries which I believe are called repeatedly for the same objects much than the others. Other possible candidates are Patrons and Items but will have to do some more digging to find out if it makes much a difference. It's easy to enable/disable by just switching out the base class for the Koha::Object and Koha::Objects derived classes.
Comment 1 David Gustafsson 2024-03-18 16:32:06 UTC
Created attachment 163357 [details] [review]
Bug 36350: Add caching for Objects::find

Add subclass of Koha::Objects that provides caching for find.

To test:
1) Ensure tests in t/db_dependend/Koha/Libraries.t passes

Sponsored-by: Gothenburg University Library
Comment 2 David Gustafsson 2024-03-18 16:37:54 UTC
Tests are only added for Libraries and should provide full testing coverage even if used for other classes, but could add a stripped down testing suite also for ItemTypes, but don't know if it would accomplish very much as the caching is also implicitly tested through the other tests for that object type.
Comment 3 David Gustafsson 2024-03-18 16:46:07 UTC
Created attachment 163361 [details] [review]
Bug 36350: Add caching for Objects::find

Add subclass of Koha::Objects that provides caching for find.

To test:
1) Ensure tests in t/db_dependend/Koha/Libraries.t passes
2) Ensure tests in t/db_dependent/Koha/ItemTypes.t passes

Sponsored-by: Gothenburg University Library
Comment 4 David Gustafsson 2024-03-25 18:50:35 UTC
Created attachment 163857 [details] [review]
Bug 36350: Add caching for Objects::find and Objects::search

Add subclass of Koha::Objects that provides cached find and search.

To test:
1) Ensure the following tests pass:
   - t/db_dependend/Koha/Libraries.t
   - t/db_dependent/Koha/ItemTypes.t
   - t/db_dependent/Koha/Patrons.t
   - t/db_dependent/Koha/Acquisition/Currencies.t

Sponsored-by: Gothenburg University Library
Comment 5 David Gustafsson 2024-03-25 18:52:46 UTC
Created attachment 163858 [details] [review]
Bug 36350: Add caching for Objects::find and Objects::search

Add subclass of Koha::Objects that provides cached find and search.

To test:
1) Ensure the following tests pass:
   - t/db_dependend/Koha/Libraries.t
   - t/db_dependent/Koha/ItemTypes.t
   - t/db_dependent/Koha/Patrons.t
   - t/db_dependent/Koha/Acquisition/Currencies.t

Sponsored-by: Gothenburg University Library
Comment 6 David Gustafsson 2024-03-25 19:16:31 UTC
Created attachment 163872 [details] [review]
Bug 36350: Add caching for Objects::find and Objects::search

Add subclass of Koha::Objects that provides cached find and search.

To test:
1) Ensure the following tests pass:
   - t/db_dependend/Koha/Libraries.t
   - t/db_dependent/Koha/ItemTypes.t
   - t/db_dependent/Koha/Patrons.t
   - t/db_dependent/Koha/Acquisition/Currencies.t

Sponsored-by: Gothenburg University Library
Comment 7 David Gustafsson 2024-03-25 19:20:41 UTC
Created attachment 163873 [details]
Before
Comment 8 David Gustafsson 2024-03-25 19:21:03 UTC
Created attachment 163874 [details]
After
Comment 9 David Gustafsson 2024-03-25 19:24:45 UTC
Added caching for Patrons and Currencies and attach a flamegraph for the acquisitions page where Patron::find and Currencies->search are called a large number of time with the same conditions. Probably only significant when having a large number of budgets, but it's an example of a page where caching can make a noticeable difference.
Comment 10 David Gustafsson 2024-03-26 17:26:24 UTC
Created attachment 163945 [details] [review]
Bug 36350: Add caching for Objects::find and Objects::search

Add subclass of Koha::Objects that provides cached find and search.

To test:
1) Ensure the following tests pass:
   - t/db_dependend/Koha/Libraries.t
   - t/db_dependent/Koha/ItemTypes.t
   - t/db_dependent/Koha/Patrons.t
   - t/db_dependent/Koha/Acquisition/Currencies.t

Sponsored-by: Gothenburg University Library
Comment 11 David Gustafsson 2024-03-26 17:28:39 UTC
Rebased on current master. The local caching of patrons in Bug 35921 is no longer needed and can be reverted.