Bug 38130 - Cannot filter items on library name
Summary: Cannot filter items on library name
Status: Pushed to stable
Alias: None
Product: Koha
Classification: Unclassified
Component: Staff interface (show other bugs)
Version: Main
Hardware: All All
: P5 - low minor
Assignee: Jonathan Druart
QA Contact: Pedro Amorim
URL:
Keywords:
Depends on: 33568
Blocks:
  Show dependency treegraph
 
Reported: 2024-10-09 07:58 UTC by Jonathan Druart
Modified: 2024-11-19 16:36 UTC (History)
5 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.11.00,24.05.06
Circulation function:


Attachments
Bug 38130: Add the ability to filter item by library name (2.62 KB, patch)
2024-10-09 08:01 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 38130: Add the ability to filter item by library name (2.68 KB, patch)
2024-10-09 14:48 UTC, Lucas Gass (lukeg)
Details | Diff | Splinter Review
Bug 38130: Add the ability to filter item by library name (2.73 KB, patch)
2024-10-09 20:18 UTC, Brendan Lawlor
Details | Diff | Splinter Review
Bug 38130: Allow sorting and filtering on library id and name (4.95 KB, patch)
2024-11-07 08:42 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 38130: Add the ability to filter item by library name (2.78 KB, patch)
2024-11-07 12:44 UTC, Pedro Amorim
Details | Diff | Splinter Review
Bug 38130: Allow sorting and filtering on library id and name (5.00 KB, patch)
2024-11-07 12:44 UTC, Pedro Amorim
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2024-10-09 07:58:51 UTC
On the item list of the bibliographic record page you actually can filter items by library, either using the dropdown list on top of the column or using the library_id (branchcode) in the global search.

But you cannot search using the library's name in the global search.
Comment 1 Jonathan Druart 2024-10-09 08:01:42 UTC
Created attachment 172559 [details] [review]
Bug 38130: Add the ability to filter item by library name

On the item list of the bibliographic record page you actually can filter
items by library, either using the dropdown list on top of the column
or using the library_id (branchcode) in the global search.

But you cannot search using the library's name in the global search.

This patch add yet other embeds to allow this.

I am not sure this is needed, we won't be able to do the same for item
type and AV, so maybe it is not worth 2 additional JOINS.

Maybe we should tell people you should use the column filters when a
dropdown list is there, instead of: "it works, sometimes".
Comment 2 Lucas Gass (lukeg) 2024-10-09 14:48:06 UTC
Created attachment 172574 [details] [review]
Bug 38130: Add the ability to filter item by library name

On the item list of the bibliographic record page you actually can filter
items by library, either using the dropdown list on top of the column
or using the library_id (branchcode) in the global search.

But you cannot search using the library's name in the global search.

This patch add yet other embeds to allow this.

I am not sure this is needed, we won't be able to do the same for item
type and AV, so maybe it is not worth 2 additional JOINS.

Maybe we should tell people you should use the column filters when a
dropdown list is there, instead of: "it works, sometimes".

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Comment 3 Brendan Lawlor 2024-10-09 20:18:57 UTC
Created attachment 172578 [details] [review]
Bug 38130: Add the ability to filter item by library name

On the item list of the bibliographic record page you actually can filter
items by library, either using the dropdown list on top of the column
or using the library_id (branchcode) in the global search.

But you cannot search using the library's name in the global search.

This patch add yet other embeds to allow this.

I am not sure this is needed, we won't be able to do the same for item
type and AV, so maybe it is not worth 2 additional JOINS.

Maybe we should tell people you should use the column filters when a
dropdown list is there, instead of: "it works, sometimes".

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Comment 4 Lucas Gass (lukeg) 2024-10-09 20:33:35 UTC
Since Brendan signed off here after me I'll use my sign-off as QA. The script is happy, the change is trivial, it makes sense, fixes the problem. 

PQA
Comment 5 Jonathan Druart 2024-10-16 13:38:56 UTC
"""
I am not sure this is needed, we won't be able to do the same for item
type and AV, so maybe it is not worth 2 additional JOINS.

Maybe we should tell people you should use the column filters when a
dropdown list is there, instead of: "it works, sometimes".
"""

I would like us to discuss this part before we push it.
Comment 6 Lucas Gass (lukeg) 2024-11-05 22:55:02 UTC
This is very similar to another bug I filed: 

https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38333

In the end, I think it is much more important to be able to sort/filter on the name/description than it would be the code. That goes for branches, item types, and any AV.
Comment 7 Lucas Gass (lukeg) 2024-11-06 16:22:57 UTC
> Maybe we should tell people you should use the column filters when a
> dropdown list is there, instead of: "it works, sometimes".
> """

Our libraries very much need to be able to sort by branch name, especially holding/home library.  

If we take Jonathan's patch and flip the order of the joins (   data: "holding_library.name:me.holding_library_id" ) it works for sorting and filtering. 

Prior to 24.05 one could not filter by branchcode, only name, so we won't be losing any previous functionality. 

We ultimately need to need to fix sorting/filtering by item type/collection as well. ( descriptions not codes ) but we are hearing from our libraries right now that home/holding library sorting/filtering is especially important.
Comment 8 Jonathan Druart 2024-11-07 08:38:41 UTC
(In reply to Lucas Gass (lukeg) from comment #7)
> > Maybe we should tell people you should use the column filters when a
> > dropdown list is there, instead of: "it works, sometimes".
> > """
> 
> Our libraries very much need to be able to sort by branch name, especially
> holding/home library.  

If we do it for the library names on this view, we need to do it for all the library columns (thinking about patrons right now but I am sure there are others). And to be consistent, for all the other coded values: "special AVs" (item types, cn source), regular AVs, patron category codes, etc.

We will introduce additional JOINs and so maybe performance problems. This needs to be investigated before we take this route IMO.
Comment 9 Jonathan Druart 2024-11-07 08:42:29 UTC
Created attachment 174103 [details] [review]
Bug 38130: Allow sorting and filtering on library id and name

On the item list of the bib detail page and the patron search we want
the library columns ('holding library', 'home library' and 'library') to
be sorted by library names and to make them searchable on library id and
name.

Concerns about this approach (comment #8):
"""
If we do it for the library names on this view, we need to do it for all the library columns (thinking about patrons right now but I am sure there are others). And to be consistent, for all the other coded values: "special AVs" (item types, cn source), regular AVs, patron category codes, etc.

We will introduce additional JOINs and so maybe performance problems. This needs to be investigated before we take this route IMO.
"""
Comment 10 Martin Renvoize (ashimema) 2024-11-07 09:59:12 UTC
So.. I advocate for some real benchmarks to actually prove the hypothesis here.

In a related query though.. I'd be interested in investigating dbic's join vs prefetch pragma's... I think some of our performance challenges come from the fact we force prefetch on the API for all embeds.  Whilst this makes sense from the perspective of having consistent data returned in the responses.. a simple join without the automatic collapse (grabbing all related fields instead of just the ones you are interested in) might be more performant for cases like this where we're not so much interested in all the fields as we are a select few.  This is again conjecture though without a benchmark.
Comment 11 Pedro Amorim 2024-11-07 12:43:14 UTC
(In reply to Jonathan Druart from comment #9)
> If we do it for the library names on this view, we need to do it for all the
> library columns (thinking about patrons right now but I am sure there are
> others). And to be consistent, for all the other coded values: "special AVs"
> (item types, cn source), regular AVs, patron category codes, etc.

Agreed.

> We will introduce additional JOINs and so maybe performance problems. This
> needs to be investigated before we take this route IMO.
> """

I've tested using Nick's randitems:
https://github.com/kidclamp/handy-koha-script/blob/main/randitems.pl


Before patches: searching for "cpl" using the datatable search input
- average of 0.27 secs for 300 items.
- average of 0.37 secs for 3000 items.

After patches: searching for "centerville" (or cpl) using the datatable search input
- average of 0.3 secs for 300 items.
- average of 0.45 secs for 3000 items.

This exercise should also be done for patrons (when that time comes) but from my testing, the performance impact seems negligible on this table.
For me, this is enough to not block this, the enhancement is clearly needed and makes sense. As a rule of thumb, anything that is displayed on the table should be retrievable by a keyword search.
Comment 12 Pedro Amorim 2024-11-07 12:44:04 UTC
Created attachment 174189 [details] [review]
Bug 38130: Add the ability to filter item by library name

On the item list of the bibliographic record page you actually can filter
items by library, either using the dropdown list on top of the column
or using the library_id (branchcode) in the global search.

But you cannot search using the library's name in the global search.

This patch add yet other embeds to allow this.

I am not sure this is needed, we won't be able to do the same for item
type and AV, so maybe it is not worth 2 additional JOINS.

Maybe we should tell people you should use the column filters when a
dropdown list is there, instead of: "it works, sometimes".

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Brendan Lawlor <blawlor@clamsnet.org>
Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Comment 13 Pedro Amorim 2024-11-07 12:44:07 UTC
Created attachment 174190 [details] [review]
Bug 38130: Allow sorting and filtering on library id and name

On the item list of the bib detail page and the patron search we want
the library columns ('holding library', 'home library' and 'library') to
be sorted by library names and to make them searchable on library id and
name.

Concerns about this approach (comment #8):
"""
If we do it for the library names on this view, we need to do it for all the library columns (thinking about patrons right now but I am sure there are others). And to be consistent, for all the other coded values: "special AVs" (item types, cn source), regular AVs, patron category codes, etc.

We will introduce additional JOINs and so maybe performance problems. This needs to be investigated before we take this route IMO.
"""

Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Comment 14 Jonathan Druart 2024-11-07 12:53:03 UTC
I am seeing, for 1000 items:
  700ms without this patch
  950ms with this patch

Also there is a bottleneck somewhere else, the UI is very slow to refresh (JS-side then).

If we are adding 150ms per JOIN and are adding 3,4 per table, it's not a good...
Comment 15 Jonathan Druart 2024-11-07 13:03:05 UTC
(In reply to Jonathan Druart from comment #14)
> Also there is a bottleneck somewhere else, the UI is very slow to refresh
> (JS-side then).

Found something, see bug 38391.
Comment 16 Pedro Amorim 2024-11-07 13:08:04 UTC
(In reply to Jonathan Druart from comment #14)
> I am seeing, for 1000 items:
>   700ms without this patch
>   950ms with this patch

Interesting, I wonder why our times differ so much, just tested again with patches still applied searching for 'centerville' 3000 items:
480ms, 434ms, 449ms, 455ms
Comment 17 Pedro Amorim 2024-11-07 13:11:33 UTC
(In reply to Jonathan Druart from comment #14)
> 
> If we are adding 150ms per JOIN and are adding 3,4 per table, it's not a
> good...

I don't think we can affirm this just yet. Additional embeds need to be added to test this (e.g. status and/or collection)
Comment 18 Jonathan Druart 2024-11-07 13:41:34 UTC
(In reply to Pedro Amorim from comment #16)
> (In reply to Jonathan Druart from comment #14)
> > I am seeing, for 1000 items:
> >   700ms without this patch
> >   950ms with this patch
> 
> Interesting, I wonder why our times differ so much, just tested again with
> patches still applied searching for 'centerville' 3000 items:
> 480ms, 434ms, 449ms, 455ms

Do you want to swap our laptops? :D
Comment 19 Jonathan Druart 2024-11-07 14:48:08 UTC
To summary PM between Pedro and me.

We should not use library's name to compare with and without the patch, we should compare with the same number of results returned (ofc!)

Tested with the following script:

use t::lib::TestBuilder;
my $builder = t::lib::TestBuilder->new;
my @branchcodes = Koha::Libraries->search->get_column('branchcode');
my $biblio = $builder->build_sample_biblio;
for my $i ( 1..1000 ) {
    say $i;
    my $branchcode = @branchcodes[int(rand(scalar @branchcodes))];
    $builder->build_sample_item({biblionumber => $biblio->biblionumber, library => $branchcode });
}
say "biblionumber=".$biblio->biblionumber;

Search "2024" in the global search to make sure 20 items will be displayed and the JOIN will happen. No need to use the column filters.

I confirm the previous numbers ~700ms without vs ~900ms with those 2 patches.
Comment 20 Jonathan Druart 2024-11-07 14:49:30 UTC
(In reply to Pedro Amorim from comment #17)
> (In reply to Jonathan Druart from comment #14)
> > 
> > If we are adding 150ms per JOIN and are adding 3,4 per table, it's not a
> > good...
> 
> I don't think we can affirm this just yet. Additional embeds need to be
> added to test this (e.g. status and/or collection)

FYI status is happening on bug 37334, but is totally different.
Comment 21 Katrin Fischer 2024-11-07 17:08:18 UTC
I'm not sure about the state of the discussion here.
Should this be pushed or are the benchmarks/performance tests a blocker?
Comment 22 Jonathan Druart 2024-11-07 20:30:31 UTC
(In reply to Katrin Fischer from comment #21)
> I'm not sure about the state of the discussion here.
> Should this be pushed or are the benchmarks/performance tests a blocker?

Not blocker.
Comment 23 Katrin Fischer 2024-11-08 10:25:01 UTC
Pushed for 24.11!

Well done everyone, thank you!
Comment 24 Lucas Gass (lukeg) 2024-11-19 16:36:01 UTC
Backported to 24.05.x for upcoming 24.05.06