Performance when iterating over deeply nested items #7245
Unanswered
hanneshoepfnerio
asked this question in
Q&A
Replies: 1 comment
-
Hello, short update on this topic. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi I've experienced some very poor loading times most probably due to my very poor code logic ;)
I solved it in another way, but I wanted to check with you if I did some major mistakes in my old approach and how it could be this slow.
So the setup was:
A collection "post", which could holds multiple images "img" which could hold multiple taxonomies "tax".
At some point in the code I needed:
For each tax, all posts which had an image which hat the same taxonomy.
I wrote a modifier where I was passing in the collection and the taxonomy. Filtering the post collection, gathering all the images, checking for its taxonomy.
It resulted in TTFB at around 2-3seconds.
Here is an abstract code example:
// template
With this approach I was not able to get any acceptable results.
I solved it writing an event listener for the assets save event.
When ever this would happen I iterated over the post and added the sum of the unique to the post itself.
Now I can just use the taxonomy entries functionality.
like so:
I was just wondering if this is a total valid approach on solving this, or if it is utterly verbose?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions