Let’s say I have a section of a page that is News. There’s a single Top Story and five Featured Stories and both are in the same Channel called News.
The way I’d do that now is
• open a exp:channel:entries loop for the single Top Story • close that loop • open a new ex:channel:entries loop for Features Stories • close that loop
that’s two queries of: SELECT channel_id FROM exp_channels WHERE channel_name = 'news'
I’m trying to optimize a page that is trying to allocate too much memory and is taking the page down (there’s a big call to a separate channel of 600+ entries that need to be displayed…i know what I need to do there, but I’m not sure how to prevent duplicate queries to the same channel).
Thanks!
edit: i should note that I’m using different Categories to differentiate between Top Story and Featured Stories
600+ entries is the real killer!
Just brainstorming- you could use either a status or a custom field instead of a category to indicate ‘top story’ and then use a single channel tag and sort it by that. You can’t sort by category since you can have more than one.
Depending on what all you need to do with the layout, you could instead handle the order in a layout- and then define a ‘top story’ layout variable and a ‘featured stories’ layout variable and then plug them into your layout.
I manage a site that calls separate channel entry tags for content in the same channel, six different instances on the home page with each instance calling a variety of statuses and/or categories to get the desired output. It’s quite a big page with content pulled from multiple channels, load time for the home page is between 1-3 seconds which is not bad.
As Robin suggested calling 600 entries is the killer, that’s a lot of stuff for any page!
One suggestion is to divide your page into multiple embed templates, each embed having x number of entries. What you then do is set cache & refresh parameters that update at slightly different periods, e.g. 60 mins for one, 65 mins for another. The idea here is all your page contents are pre-cached so they should load faster, and in theory you may be able to load 100’s of entries into a page with an acceptable load time.
The other thing to mention, are you using the disable= parameter to reduce DB queries? They’re always worth adding https://docs.expressionengine.com/latest/channels/entries.html#disable
Thanks Rob, good ideas there. The embedded template strategy is interesting. I’ll test that out.
My problem with the 600+ entries is that PHP actually runs out of memory and I already have my memory_limit in php.ini set pretty high. I tried pulling that out to an embedded template but it still has the same problem even if it’s the only query in a template. I tried paginating the list thinking that might run partial queries when you click through the pagination links but that doesn’t seem to be how it works.
I don’t know of any great way to solve that issue.
The multi embed approach can work in some circumstances, it’s always worth testing different methods!
Another thing to try is outputting fewer custom fields, for instance do you really need a date with every news entry. Reducing the amount of data you’re querying can sometimes give positive results.
I think I’d start running some tests to see what your maximum entry limit is until you run out of memory. Test with 100 entries, 200 entries and so on until it fails. That would give you an indication of how much your server can actually handle.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.