4

I have a channel listing characters in a TV show. On the index page of that channel, I display a visual index to all characters. The index looks like this and it uses Solspace's Tags module to pick out the image for each character:

<ul>
{exp:channel:entries channel="{current_channel}" limit="500" orderby="title" sort="asc" disable="member_data|pagination"}
<li>
<div class="CharIndexItem">
<div class="CharIndexImage">
{embed="Characters/Snippet_Image_index_GoT" character="{title}" byname="{{current_channel_id}_byname}" actor="{{current_channel_id}_actor_name}"}
</div>
<div class="CharIndexText"><a href="{comment_url_title_auto_path}">{title}</a></div>
</div>
</li>
{/exp:channel:entries}
</ul>

And the embed like this:

{exp:tag:entries channel="channel42" limit="1" tag="{embed:character} Index"}
<a href="{comment_entry_id_auto_path}"><img src="{42_image:small}" border="0" title="{embed:character}{if embed:byname != ""}, {embed:byname}{/if}{if embed:actor != ""}, played by {embed:actor}{/if}" /></a>
{/exp:tag:entries} 

Now, since the show has a lot of characters, that index ends up with a lot of embeds. Right now it isn't a problem, but the site gets hit with very heavy traffic when the show is on air, so I am thinking it may cause an issue then. Is there any way to cut back on these embeds? I do need to stay with Tags as the method of marking the images that get used for each character, it is the only workflow that really makes sense.

  • 1
    Have you thought about using Stash for this? – Natetronn Dec 1 '12 at 22:58
  • I am not familiar with Stash, I will have a look into it, thanks. :) – Linda Antonsson Dec 1 '12 at 23:04
7

If performance is only a problem when the site gets hit by a lot of traffic, you might want to turn on caching for that particular tag (I'm not really a fan of full page caching). That is what it is meant for...

{exp:channel:entries cache='yes' refresh='60' ...}

Might I ask why you have at all? You shouldn't need it since you are not nesting the same tags... if it is because you use this snippet in multiple places, might I suggest using a snippet?

– Wouter

| improve this answer | |
  • The channel:entries pair shares variables with tag:entries, so using tag:entries in the same template did not pass the correct values to it. So it does seem like it needs to broken out, at least per Solspace's support. – Linda Antonsson Dec 1 '12 at 23:19
  • In that case, caching the entire tag would be your best bet: {exp:channel:entries cache='yes' refresh='60' ...} (refresh is in minutes). – Wouter Vervloet Dec 1 '12 at 23:22
  • Alright, thanks. :) From reading a bit, I had thought that avoiding embeds at all costs was the thing to focus on, but just caching the tag seems like the easier approach. – Linda Antonsson Dec 2 '12 at 9:47
  • Well... cutting down on the number of embeds and minimizing caching is 'the best way' (there is no right way in EE), but as a quick fix caching can be helpful. If you ever have the time I'd suggest finding other ways of solving your performance problems, just to further your understanding of how EE handles things. This way you can avoid these issues in future projects. – Wouter Vervloet Dec 12 '12 at 17:11
1

There's also a few other, more effective ways to cache code chunks like that such as CE Cache or Template Morsels.

| improve this answer | |
  • 1
    In this case it would be better to simply turn on caching for the embed templates. – Isaac Raway Dec 2 '12 at 6:35
1

The easiest thing to do in this case I would recommend simply turning on caching for the embed templates. You will need to specify how long cached versions of the embeds should be saved.

You could also make sure on my CacheCracker add-on to help manage and expire the cached template's data automatically when publishing new entries in the associated channels.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.