You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have thousands of pages in my app, but my global menu is - by design - only showing around 40 pages (depth: 0 and depth: 1) in a simple nested structure. Up until now I've used a menu presenter that inherits from the Refinery menu presenter, but I've now tried to remove the presenter and do this instead (kinda messy, but works):
My presenter could probably have been tuned, but it was using 2000 sql queries for each request to build the menu*, and for such a simple structure a presenter seemed like overkill anyway (also, I don't really like the presenter pattern). The above setup instead uses a modest 5 sql queries.
So far, so good. But url_for(page) creates links like /pages/studies and /pages/dance instead of nested slugs like /studies and /studies/dance, which is a problem. So I tried to use the url method on the iteration itself (i.e. single.url instead of url_for(single)), and it works, but it introduced an N+1 problem and I now have 41 queries (one for each menu_page).
Is it possible to avoid this while keeping pretty nested urls? Is there a better method to use or anything that the controller can eager load that alleviates this?
*obviously I use caching here, but invalidation is way more expensive than it has to be.
The text was updated successfully, but these errors were encountered:
I have thousands of pages in my app, but my global menu is - by design - only showing around 40 pages (depth: 0 and depth: 1) in a simple nested structure. Up until now I've used a menu presenter that inherits from the Refinery menu presenter, but I've now tried to remove the presenter and do this instead (kinda messy, but works):
Then call a simple partial from the application layout itself:
My presenter could probably have been tuned, but it was using 2000 sql queries for each request to build the menu*, and for such a simple structure a presenter seemed like overkill anyway (also, I don't really like the presenter pattern). The above setup instead uses a modest 5 sql queries.
So far, so good. But
url_for(page)
creates links like/pages/studies
and/pages/dance
instead of nested slugs like/studies
and/studies/dance
, which is a problem. So I tried to use theurl
method on the iteration itself (i.e.single.url
instead ofurl_for(single)
), and it works, but it introduced an N+1 problem and I now have 41 queries (one for each menu_page).Is it possible to avoid this while keeping pretty nested urls? Is there a better method to use or anything that the controller can eager load that alleviates this?
*obviously I use caching here, but invalidation is way more expensive than it has to be.
The text was updated successfully, but these errors were encountered: