Agency: Preload agency ancestors in the API to fix N+1 query#2576
Agency: Preload agency ancestors in the API to fix N+1 query#2576Tschuppi81 wants to merge 9 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
|
We probably have the same issue for the |
|
Correct, I didn't follow the observer path(s) as it seems quite complex to me (I could open a ticket for it to follow-up on this). Especially in case of moving an element or rename one the whole subtree's paths would need to be walked. |
You only need to touch the cache of your descendents when either your name or your parent changes, your observer is responsible for propagating the change to your descendants, it should be pretty straightforward, especially if we don't care about it being slow, since we shouldn't be changing multiple parents/names in one transaction. The most straightforward, but slightly inefficient way would be putting one observer on Manually prefetching the descendants for some collections is a lot more complex and it only helps, if you remember to do it. Ideally in a collection context we should never be looking at the rest of the tree from individual nodes. Whenever we do, it makes more sense to just prefetch and cache the entire tree in a single query, like we already do for pages for the sidebar navigation. |
|
So you prefer the observer path over the current |
|
Yes, since it will help us everywhere we're linking to these models, including places like search results and breadcrumbs. |
Agency: Preload agency ancestors in the API to fix N+1 query
Building the
htmllink of each agency renders its full path, which walks up the parent chain. Only the direct parent was eager loaded, so every ancestor above it was loaded with its own query. Preload the ancestor closure in bulk instead.TYPE: Performance
LINK: https://seantis-gmbh.sentry.io/issues/7426519446