Bug 34223

Summary: ILL status filter does not load immediately after selecting a backend filter
Product: Koha Reporter: Laura Escamilla <Laura.escamilla>
Component: ILLAssignee: Martin Renvoize (ashimema) <martin.renvoize>
Status: RESOLVED FIXED QA Contact: Katrin Fischer <katrin.fischer>
Severity: normal    
Priority: P5 - low CC: fridolin.somers, magnus, martin.renvoize, nick, pedro.amorim, tomascohen
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Small patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
23.11.00,23.05.04,22.11.10
Circulation function:
Bug Depends on: 22440    
Bug Blocks: 34431    
Attachments: Bug 34223: PROOF OF CONCEPT
Bug 34223: Fix filter performance
Bug 34223: Fix filter performance
Bug 34223: Work around ONLY_FULL_GROUP_BY in Illbackend
Bug 34223: (follow-up) Restore status_alias handling
Bug 34223: Work around ONLY_FULL_GROUP_BY in Illbackend
Bug 34223: (follow-up) Restore status_alias handling
Bug 34223: Add unit test for existing_statuses
Bug 34223: Add unit test for existing_statuses
Bug 34223: (follow-up) Mock backend in tests
Bug 34223: Work around ONLY_FULL_GROUP_BY in Illbackend
Bug 34223: (follow-up) Restore status_alias handling
Bug 34223: Add unit test for existing_statuses
Bug 34223: (follow-up) Mock backend in tests
Bug 34223: (follow-up) Mock backend in tests
Bug 34223: Work around ONLY_FULL_GROUP_BY in Illbackend
Bug 34223: (follow-up) Restore status_alias handling
Bug 34223: Add unit test for existing_statuses
Bug 34223: (follow-up) Mock backend in tests
Bug 34223: Work around ONLY_FULL_GROUP_BY in Illbackend
Bug 34223: (follow-up) Restore status_alias handling
Bug 34223: Add unit test for existing_statuses
Bug 34223: (follow-up) Mock backend in tests
Bug 34223: Work around ONLY_FULL_GROUP_BY in Illbackend
Bug 34223: (follow-up) Restore status_alias handling
Bug 34223: Add unit test for existing_statuses
Bug 34223: (follow-up) Mock backend in tests
Bug 34223: (QA follow-up) Fix file permissions
Bug 34223: (follow-up) Ensure consistent ordering of statuses

Description Laura Escamilla 2023-07-06 20:38:50 UTC
Selecting a backend filter in ILL is required in order for the status filter to become enabled. Once a provider is chosen in the backend filter, it takes the status filter around 7s to populate instead of populating immediately. This is confusing to staff members and can also disrupt the workflow.
Comment 1 Pedro Amorim 2023-07-06 22:48:27 UTC
The solution I found for this at the time was prevented, I believe, by ONLY_FULL_GROUP_BY in
https://git.koha-community.org/Koha-community/Koha/src/branch/master/Koha/Database.pm#L106

There is currently a FIXME in https://github.com/Koha-Community/Koha/blob/master/Koha/Illbackend.pm
This FIXME is for the samne issue reported by this bug.

Need help with this.
Comment 2 Pedro Amorim 2023-07-10 17:03:55 UTC
Created attachment 153289 [details] [review]
Bug 34223: PROOF OF CONCEPT

The following command will (hopefully) reset your ILL data and create 10k fake ILL requests (run this in DEV KTD only).

1) On an empty k-t-d, run:
bash <(curl -s https://raw.githubusercontent.com/ammopt/koha-ill-dev/master/start-ill-dev-data.sh)
2) Pet a cat
3) Visit /cgi-bin/koha/ill/ill-requests.pl and select a backend on the left side filters
4) Notice how the status filter takes a while (3-5 secs) to load
5) Apply patch and koha-plack --restart kohadev
6) Repeat 3, notice how the status filter now loads fast
Comment 3 Pedro Amorim 2023-07-10 17:05:29 UTC
The patch is just a proof of concept detailing the solution I had at the time of developing this but was ultimately prevented by the ONLY_FULL_GROUP_BY.

The patch is NOT the fix, as I don't think we want to change Database.pm for this. It's just demonstrating how it should work.
Comment 4 Pedro Amorim 2023-07-27 09:40:22 UTC
Created attachment 153953 [details] [review]
Bug 34223: Fix filter performance

We are now only fetching the existing statuses for the provided backend.
Then, we fetch 1 illrequest object to make use of ->strings_map.
Before, we were fetching all illrequests in the database and removing redundant afterwards
Comment 5 Pedro Amorim 2023-07-27 09:51:15 UTC
@Laura Escamilla

Can you test my most recent patch? I've tested it myself with 10k fake requests and it fixed the issue.
Comment 6 Pedro Amorim 2023-07-27 09:58:06 UTC
Found an issue with the patch. Trying to fix.
Comment 7 Pedro Amorim 2023-07-27 10:07:04 UTC
Created attachment 153956 [details] [review]
Bug 34223: Fix filter performance

We are now only fetching the existing statuses for the provided backend.
Then, we fetch 1 illrequest object to make use of ->strings_map.
Before, we were fetching all illrequests in the database and removing redundant afterwards
Comment 8 Martin Renvoize (ashimema) 2023-07-27 10:20:56 UTC
Created attachment 153957 [details] [review]
Bug 34223: Work around ONLY_FULL_GROUP_BY in Illbackend

This patch re-works the query in the existing_statuses method to remove
the FIXME and improve performance.  We pass an SQL literal into the
query to make it explicit which illrequest_id we're looking for (which
dampens the SQL warning) even though we really don't mind which request
is returned here.

Test plan:

The following command will (hopefully) reset your ILL data and create 10k fake ILL requests (run this in DEV KTD only).

1) On an empty k-t-d, run:
bash <(curl -s https://raw.githubusercontent.com/ammopt/koha-ill-dev/master/start-ill-dev-data.sh)
2) Pet a cat
3) Visit /cgi-bin/koha/ill/ill-requests.pl and select a backend on the left side filters
4) Notice how the status filter takes a while (3-5 secs) to load
5) Apply patch and koha-plack --restart kohadev
6) Repeat 3, notice how the status filter now loads fast
Comment 9 Martin Renvoize (ashimema) 2023-07-27 10:23:05 UTC
Pedro and I had another look at this and I managed to come up with a slightly cleaner and I believe more performant alternative now attached above.

We're not getting just the status's we want in just one DB hit.. it's a fun work around for the `ONLY_FULL_GROUP_BY` problem.

Please test as per Pedro's test plan.. now copied into my submission too.
Comment 10 Martin Renvoize (ashimema) 2023-07-27 11:07:06 UTC
Issue spotted.. Just merging parts of Pedro's patch and parts of my own and we'll cross-sign each others.

Also.. there appears to be no unit tests for this method.. so I'm going to have a look at writing one.
Comment 11 Martin Renvoize (ashimema) 2023-07-27 11:27:05 UTC
Created attachment 153961 [details] [review]
Bug 34223: (follow-up) Restore status_alias handling

By reducing the original call to all distinct 'status' we also removed
the status_alias combinations. This patch adds an additional distinct
query to fetch all 'status_alias' and add them to the returned data
structure.
Comment 12 Martin Renvoize (ashimema) 2023-07-27 11:44:28 UTC
Created attachment 153962 [details] [review]
Bug 34223: Work around ONLY_FULL_GROUP_BY in Illbackend

This patch re-works the query in the existing_statuses method to remove
the FIXME and improve performance.  We pass an SQL literal into the
query to make it explicit which illrequest_id we're looking for (which
dampens the SQL warning) even though we really don't mind which request
is returned here.

Test plan:

The following command will (hopefully) reset your ILL data and create 10k fake ILL requests (run this in DEV KTD only).

1) On an empty k-t-d, run:
bash <(curl -s https://raw.githubusercontent.com/ammopt/koha-ill-dev/master/start-ill-dev-data.sh)
2) Pet a cat
3) Visit /cgi-bin/koha/ill/ill-requests.pl and select a backend on the left side filters
4) Notice how the status filter takes a while (3-5 secs) to load
5) Apply patch and koha-plack --restart kohadev
6) Repeat 3, notice how the status filter now loads fast

Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Comment 13 Martin Renvoize (ashimema) 2023-07-27 11:44:30 UTC
Created attachment 153963 [details] [review]
Bug 34223: (follow-up) Restore status_alias handling

By reducing the original call to all distinct 'status' we also removed
the status_alias combinations. This patch adds an additional distinct
query to fetch all 'status_alias' and add them to the returned data
structure.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 14 Martin Renvoize (ashimema) 2023-07-27 12:32:34 UTC
Created attachment 153968 [details] [review]
Bug 34223: Add unit test for existing_statuses

This patch adds a unit test for the 'existing_statuses' method.
Comment 15 Martin Renvoize (ashimema) 2023-07-27 13:18:16 UTC
Created attachment 153973 [details] [review]
Bug 34223: Add unit test for existing_statuses

This patch adds a unit test for the 'existing_statuses' method.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 16 Pedro Amorim 2023-07-27 13:56:00 UTC
Created attachment 153978 [details] [review]
Bug 34223: (follow-up) Mock backend in tests

Add a new request with a backend specific status
Comment 17 Laura Escamilla 2023-07-27 13:57:16 UTC
Created attachment 153979 [details] [review]
Bug 34223: Work around ONLY_FULL_GROUP_BY in Illbackend

This patch re-works the query in the existing_statuses method to remove
the FIXME and improve performance.  We pass an SQL literal into the
query to make it explicit which illrequest_id we're looking for (which
dampens the SQL warning) even though we really don't mind which request
is returned here.

Test plan:

The following command will (hopefully) reset your ILL data and create 10k fake ILL requests (run this in DEV KTD only).

1) On an empty k-t-d, run:
bash <(curl -s https://raw.githubusercontent.com/ammopt/koha-ill-dev/master/start-ill-dev-data.sh)
2) Pet a cat
3) Visit /cgi-bin/koha/ill/ill-requests.pl and select a backend on the left side filters
4) Notice how the status filter takes a while (3-5 secs) to load
5) Apply patch and koha-plack --restart kohadev
6) Repeat 3, notice how the status filter now loads fast

Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Comment 18 Laura Escamilla 2023-07-27 13:57:26 UTC
Created attachment 153980 [details] [review]
Bug 34223: (follow-up) Restore status_alias handling

By reducing the original call to all distinct 'status' we also removed
the status_alias combinations. This patch adds an additional distinct
query to fetch all 'status_alias' and add them to the returned data
structure.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Comment 19 Laura Escamilla 2023-07-27 13:57:28 UTC
Created attachment 153981 [details] [review]
Bug 34223: Add unit test for existing_statuses

This patch adds a unit test for the 'existing_statuses' method.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Comment 20 Pedro Amorim 2023-07-27 14:20:36 UTC
Created attachment 153989 [details] [review]
Bug 34223: (follow-up) Mock backend in tests

Add a new request with a backend specific status
Comment 21 Pedro Amorim 2023-07-27 14:23:33 UTC
Created attachment 153990 [details] [review]
Bug 34223: (follow-up) Mock backend in tests

Add a new request with a backend specific status
Comment 22 Pedro Amorim 2023-07-28 09:36:30 UTC
Created attachment 154026 [details] [review]
Bug 34223: Work around ONLY_FULL_GROUP_BY in Illbackend

This patch re-works the query in the existing_statuses method to remove
the FIXME and improve performance.  We pass an SQL literal into the
query to make it explicit which illrequest_id we're looking for (which
dampens the SQL warning) even though we really don't mind which request
is returned here.

Test plan:

The following command will (hopefully) reset your ILL data and create 10k fake ILL requests (run this in DEV KTD only).

1) On an empty k-t-d, run:
bash <(curl -s https://raw.githubusercontent.com/ammopt/koha-ill-dev/master/start-ill-dev-data.sh)
2) Pet a cat
3) Visit /cgi-bin/koha/ill/ill-requests.pl and select a backend on the left side filters
4) Notice how the status filter takes a while (3-5 secs) to load
5) Apply patch and koha-plack --restart kohadev
6) Repeat 3, notice how the status filter now loads fast

Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Comment 23 Pedro Amorim 2023-07-28 09:36:33 UTC
Created attachment 154027 [details] [review]
Bug 34223: (follow-up) Restore status_alias handling

By reducing the original call to all distinct 'status' we also removed
the status_alias combinations. This patch adds an additional distinct
query to fetch all 'status_alias' and add them to the returned data
structure.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Comment 24 Pedro Amorim 2023-07-28 09:36:36 UTC
Created attachment 154028 [details] [review]
Bug 34223: Add unit test for existing_statuses

This patch adds a unit test for the 'existing_statuses' method.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Comment 25 Pedro Amorim 2023-07-28 09:36:39 UTC
Created attachment 154029 [details] [review]
Bug 34223: (follow-up) Mock backend in tests

Add a new request with a backend specific status

Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Comment 26 Pedro Amorim 2023-07-28 09:40:36 UTC
It appears something went wrong with patch "Add unit test for existing_statuses" upon Laura's sign-off, it currently includes all other patches AND Illbackend.t (which is the only file it should contain).
Comment 27 Pedro Amorim 2023-07-28 09:45:59 UTC
Created attachment 154030 [details] [review]
Bug 34223: Work around ONLY_FULL_GROUP_BY in Illbackend

This patch re-works the query in the existing_statuses method to remove
the FIXME and improve performance.  We pass an SQL literal into the
query to make it explicit which illrequest_id we're looking for (which
dampens the SQL warning) even though we really don't mind which request
is returned here.

Test plan:

The following command will (hopefully) reset your ILL data and create 10k fake ILL requests (run this in DEV KTD only).

1) On an empty k-t-d, run:
bash <(curl -s https://raw.githubusercontent.com/ammopt/koha-ill-dev/master/start-ill-dev-data.sh)
2) Pet a cat
3) Visit /cgi-bin/koha/ill/ill-requests.pl and select a backend on the left side filters
4) Notice how the status filter takes a while (3-5 secs) to load
5) Apply patch and koha-plack --restart kohadev
6) Repeat 3, notice how the status filter now loads fast

Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Comment 28 Pedro Amorim 2023-07-28 09:46:02 UTC
Created attachment 154031 [details] [review]
Bug 34223: (follow-up) Restore status_alias handling

By reducing the original call to all distinct 'status' we also removed
the status_alias combinations. This patch adds an additional distinct
query to fetch all 'status_alias' and add them to the returned data
structure.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Comment 29 Pedro Amorim 2023-07-28 09:46:05 UTC
Created attachment 154032 [details] [review]
Bug 34223: Add unit test for existing_statuses

This patch adds a unit test for the 'existing_statuses' method.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Comment 30 Pedro Amorim 2023-07-28 09:46:08 UTC
Created attachment 154033 [details] [review]
Bug 34223: (follow-up) Mock backend in tests

Add a new request with a backend specific status

Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Comment 31 Katrin Fischer 2023-07-29 21:30:08 UTC
Created attachment 154068 [details] [review]
Bug 34223: Work around ONLY_FULL_GROUP_BY in Illbackend

This patch re-works the query in the existing_statuses method to remove
the FIXME and improve performance.  We pass an SQL literal into the
query to make it explicit which illrequest_id we're looking for (which
dampens the SQL warning) even though we really don't mind which request
is returned here.

Test plan:

The following command will (hopefully) reset your ILL data and create 10k fake ILL requests (run this in DEV KTD only).

1) On an empty k-t-d, run:
bash <(curl -s https://raw.githubusercontent.com/ammopt/koha-ill-dev/master/start-ill-dev-data.sh)
2) Pet a cat
3) Visit /cgi-bin/koha/ill/ill-requests.pl and select a backend on the left side filters
4) Notice how the status filter takes a while (3-5 secs) to load
5) Apply patch and koha-plack --restart kohadev
6) Repeat 3, notice how the status filter now loads fast

Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Comment 32 Katrin Fischer 2023-07-29 21:30:11 UTC
Created attachment 154069 [details] [review]
Bug 34223: (follow-up) Restore status_alias handling

By reducing the original call to all distinct 'status' we also removed
the status_alias combinations. This patch adds an additional distinct
query to fetch all 'status_alias' and add them to the returned data
structure.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Comment 33 Katrin Fischer 2023-07-29 21:30:14 UTC
Created attachment 154070 [details] [review]
Bug 34223: Add unit test for existing_statuses

This patch adds a unit test for the 'existing_statuses' method.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Laura Escamilla <laura.escamilla@bywatersolutions.com>
Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 34 Katrin Fischer 2023-07-29 21:30:17 UTC
Created attachment 154071 [details] [review]
Bug 34223: (follow-up) Mock backend in tests

Add a new request with a backend specific status

Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 35 Katrin Fischer 2023-07-29 21:31:45 UTC
I almost got stuck on step 2... no cat!
Comment 36 Tomás Cohen Arazi (tcohen) 2023-09-06 18:10:57 UTC
Pushed to master for 23.11.

Nice work everyone, thanks!
Comment 37 Tomás Cohen Arazi (tcohen) 2023-09-06 19:47:33 UTC
Created attachment 155280 [details] [review]
Bug 34223: (QA follow-up) Fix file permissions

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 38 Fridolin Somers 2023-09-08 19:29:48 UTC
Pushed to 23.05.x for 23.05.04
Comment 39 Martin Renvoize (ashimema) 2023-09-11 13:53:09 UTC
Created attachment 155493 [details] [review]
Bug 34223: (follow-up) Ensure consistent ordering of statuses

This patch adds an order_by clause to ensure consistent ordering of the
returned status and status_alias statuses from the database between
MySQL 8 and other DB engines.

This fixes the failing tests introducd in bug 34223.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 40 Tomás Cohen Arazi (tcohen) 2023-09-12 12:49:03 UTC
Follow-up pushed to master. Please backport.
Comment 41 Fridolin Somers 2023-09-14 18:24:12 UTC
Follow-up pushed to 23.05.x for 23.05.04
Comment 42 Matt Blenkinsop 2023-09-15 09:51:02 UTC
Nice work everyone!

Pushed to oldstable for 22.11.x