Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@root913
Copy link
Contributor

@root913 root913 commented Jul 12, 2025

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.

@github-actions
Copy link

Review Checklist

  • Target branch (11.5 for bug fixes, others 12.x)
  • Tests (if it's testable code, there should be a test for it - get help)
  • Docs (every functionality needs to be documented, see here)
  • Migration incl. install.sql (e.g. if the database schema changes, ...)
  • Upgrade notes (deprecations, important information, migration hints, ...)
  • Label
  • Milestone

@fashxp
Copy link
Member

fashxp commented Jul 17, 2025

thx very much.
changes look good to me. could you please have a quick look at sonar cube and reduce the line lengths of these two lines.

@jdreesen
Copy link
Contributor

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.

Unfortunately, Pimcore uses N+1 almost everywhere. It would be awesome if someone would tackle this topic!

@root913
Copy link
Contributor Author

root913 commented Jul 17, 2025

thx very much. changes look good to me. could you please have a quick look at sonar cube and reduce the line lengths of these two lines.

Yes - working on it.


$tags = array_filter($tags);
$list = new Listing();
$list->setCondition("`id` IN ('" . implode("','", $tagIds) . "')");
Copy link
Member

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?

Copy link
Contributor

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:

Suggested change
$list->setCondition("`id` IN ('" . implode("','", $tagIds) . "')");
$list->setCondition("`id` IN (?)", [$tagIds]);

@sonarqubecloud
Copy link

@root913 root913 requested a review from jdreesen July 23, 2025 14:11
@root913 root913 requested a review from fashxp July 24, 2025 09:43
@fashxp
Copy link
Member

fashxp commented Jul 24, 2025

thx very much!!

@fashxp fashxp added this to the 12.2.0 milestone Jul 24, 2025
@fashxp fashxp merged commit 4be1b85 into pimcore:12.x Jul 24, 2025
13 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jul 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants