Bug 29859 - Favor iterators over as_list
Summary: Favor iterators over as_list
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Jonathan Druart
QA Contact: Martin Renvoize
URL:
Keywords:
Depends on: 29844
Blocks:
  Show dependency treegraph
 
Reported: 2022-01-12 13:55 UTC by Jonathan Druart
Modified: 2022-12-12 21:24 UTC (History)
5 users (show)

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


Attachments
Bug 29859: Use iterator instead of as_list (56.13 KB, patch)
2022-01-12 13:57 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 29859: Use iterator instead of as_list (56.90 KB, patch)
2022-01-12 14:41 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 29859: Use iterator instead of as_list (56.95 KB, patch)
2022-02-02 13:28 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 29859: Use iterator instead of as_list (57.01 KB, patch)
2022-02-03 15:13 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 29859: (QA follow-up) Minor typo correction (900 bytes, patch)
2022-02-03 15:13 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 29859: (follow-up) Use iterator instead of as_list (916 bytes, patch)
2022-02-11 08:16 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 29859: Fix currencies display (1.63 KB, patch)
2022-02-11 09:24 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 29859: Fix club/enroll (1.36 KB, patch)
2022-04-05 13:19 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 29859: Fix BatchUpdateAuthority (1021 bytes, patch)
2022-04-06 09:36 UTC, Jonathan Druart
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2022-01-12 13:55:21 UTC
On bug 29844 we decided to remove wantarray from Koha::Objects->search. Reviewing the difference occurrences I found some unnecessary uses of ->as_list, where iterators should be used instead.
Comment 1 Jonathan Druart 2022-01-12 13:57:24 UTC
Created attachment 129346 [details] [review]
Bug 29859: Use iterator instead of as_list

On bug 29844 we decided to remove wantarray from Koha::Objects->search.
Reviewing the difference occurrences I found some unnecessary uses of ->as_list,
where iterators should be used instead.

This patch only removes the obvious places, not the tricky ones.
Comment 2 Jonathan Druart 2022-01-12 13:57:54 UTC
There is a non-squashed version on https://gitlab.com/joubu/Koha/-/tree/bug_29859
Comment 3 Jonathan Druart 2022-01-12 14:41:34 UTC
Created attachment 129350 [details] [review]
Bug 29859: Use iterator instead of as_list

On bug 29844 we decided to remove wantarray from Koha::Objects->search.
Reviewing the difference occurrences I found some unnecessary uses of ->as_list,
where iterators should be used instead.

This patch only removes the obvious places, not the tricky ones.
Comment 4 Tomás Cohen Arazi 2022-02-02 13:28:12 UTC
Created attachment 130102 [details] [review]
Bug 29859: Use iterator instead of as_list

On bug 29844 we decided to remove wantarray from Koha::Objects->search.
Reviewing the difference occurrences I found some unnecessary uses of ->as_list,
where iterators should be used instead.

This patch only removes the obvious places, not the tricky ones.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 5 Martin Renvoize 2022-02-03 14:30:44 UTC
Comment on attachment 130102 [details] [review]
Bug 29859: Use iterator instead of as_list

Review of attachment 130102 [details] [review]:
-----------------------------------------------------------------

We introduce a few .count calls in templates here.. which will add a DB hit per call unless I'm mistaken?

Now, I don't think a count call has much impact on performance, but it may be worth taking into consideration at some point.. for the pattern [% IF whatevers.count %]boiler[% FOREACH whatever IN whatever %]list of stuff[% END %][% END %] we could perhaps just add the boiler in the first iteration of the loop using the 'first' or 'index' methods of the TT iterator? instead of testing for count explicitly?

::: Koha/Holds.pm
@@ +122,5 @@
> +        {
> +            columns  => ['itemnumber'],
> +            collapse => 1,
> +        }
> +    )->get_columns('itemnumber');

get_column vs get_columns
Comment 6 Martin Renvoize 2022-02-03 15:13:20 UTC
Created attachment 130148 [details] [review]
Bug 29859: Use iterator instead of as_list

On bug 29844 we decided to remove wantarray from Koha::Objects->search.
Reviewing the difference occurrences I found some unnecessary uses of ->as_list,
where iterators should be used instead.

This patch only removes the obvious places, not the tricky ones.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 7 Martin Renvoize 2022-02-03 15:13:23 UTC
Created attachment 130149 [details] [review]
Bug 29859: (QA follow-up) Minor typo correction

We introduced a tiny bug with a typo in the patchset, the accessor
method is called 'get_column' not 'get_columns'.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 8 Martin Renvoize 2022-02-03 15:14:44 UTC
A nice improvement.. I fixed the minor typo with a followup and moved the discussion around .count vs loop variables to a new bug.

QA scripts are happy and I couldn't find any errors in the UI.

Passing QA
Comment 9 Fridolin Somers 2022-02-10 01:36:36 UTC
Pushed to master for 22.05, thanks to everybody involved 🦄
Comment 10 Jonathan Druart 2022-02-11 08:16:28 UTC
Created attachment 130480 [details] [review]
Bug 29859: (follow-up) Use iterator instead of as_list
Comment 11 Jonathan Druart 2022-02-11 09:24:54 UTC
Created attachment 130483 [details] [review]
Bug 29859: Fix currencies display

Oops!
Comment 12 Fridolin Somers 2022-02-11 18:51:06 UTC
> Bug 29859: (follow-up) Use iterator instead of as_list 
> Bug 29859: Fix currencies display
Pushed to master
Comment 13 Jonathan Druart 2022-04-05 13:19:37 UTC
Created attachment 132972 [details] [review]
Bug 29859: Fix club/enroll
Comment 14 Fridolin Somers 2022-04-05 15:10:30 UTC
> Bug 29859: Fix club/enroll
Pushed to master
Comment 15 Jonathan Druart 2022-04-06 09:36:29 UTC
Created attachment 132983 [details] [review]
Bug 29859: Fix BatchUpdateAuthority

Use of inherited AUTOLOAD for non-method Koha::BackgroundJob::BatchUpdateAuthority::ModAuthority() is
no longer allowed
Comment 16 Fridolin Somers 2022-04-07 07:40:37 UTC
> Bug 29859: Fix BatchUpdateAuthority
Pushed to master
Comment 17 Jonathan Druart 2022-04-07 08:16:29 UTC
(In reply to Fridolin Somers from comment #16)
> > Bug 29859: Fix BatchUpdateAuthority
> Pushed to master

I obsoleted this.(In reply to Fridolin Somers from comment #16)
> > Bug 29859: Fix BatchUpdateAuthority
> Pushed to master

Hum? This patch was marked as obsolete, it shouldn't have been pushed. It was a mistake to attach it here. See bug 30461.
Comment 18 Fridolin Somers 2022-04-12 15:22:36 UTC
Comment on attachment 132983 [details] [review]
Bug 29859: Fix BatchUpdateAuthority

Ah ok, reverted from master