-
Couldn't load subscription status.
- Fork 1.5k
[Improvement]: Reduce N+1 Queries in Notes and Tags listing #18548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Improvement]: Reduce N+1 Queries in Notes and Tags listing #18548
Conversation
Review Checklist
|
|
thx very much. |
Unfortunately, Pimcore uses N+1 almost everywhere. It would be awesome if someone would tackle this topic! |
Yes - working on it. |
…ndle empty input cases in loadDataList and getTagsForElement methods
models/Element/Tag/Dao.php
Outdated
|
|
||
| $tags = array_filter($tags); | ||
| $list = new Listing(); | ||
| $list->setCondition("`id` IN ('" . implode("','", $tagIds) . "')"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use $db->quote here just to be safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the tag IDs? They come directly from an integer column in the database, so it should be safe.
But if you want to escape them, we should probably use prepared statements here as well:
| $list->setCondition("`id` IN ('" . implode("','", $tagIds) . "')"); | |
| $list->setCondition("`id` IN (?)", [$tagIds]); |
Co-authored-by: Jacob Dreesen <[email protected]>
…ent method, added missing getConditionVariableTypes
|
|
thx very much!! |
This PR introduces a performance enhancement by eliminating N+1 query patterns in the Notes and Tags listing.
Before this change notes/tags listings were loading list of ids and then in loop getById was used to return model from database - this is causing many unnessesary queries. For example to load 100 tags it would generate 1 + 100 queries.
While working on this PR, I identified similar N+1 query issues in other Pimcore models (e.g., [Email/Log, Schedule/Task, Recyclebin, Site, DataObject, Document, Asset, Classificationstore/StoreConfig]). These are outside the scope of this PR, but may benefit from similar performance improvements in future contributions.