ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Complex category help urgently needed!

January 29, 2011 4:40am

Subscribe [4]
  • #1 / Jan 29, 2011 4:40am

    Paul_B

    86 posts

    Hi - I’m building a store with EE1.7 & Cartthrob, and have moved it to enginehosting, but I’m having some serious performance issues and I think it might be down to the way I’m inefficiently handling certain areas of code. The bit I’m most concerned about is this:

    The site sells jewellery and has a set of categories for brands, and another set of categories for jewellery types. On a brand page, I need to list the jewellery types relevant to that brand only (and generate the relevant link paths). So only type categories that have entries against them and the brand return a link.

    The way I’ve ended up doing it is with an exp:weblog:categories tag, and an embedded weblog:entries tag inside it that will return the jewellery type only if there are entries within it. This seems to be a hideously expensive way of doing it; I’m wondering if I could achieve a more efficient list with the query module, but I can’t figure out how to write the query. here’s my code:

    {exp:weblog:categories weblog="jewellery" category_group="8" show_empty="no"}
        {embed="_components/.product_nav_list" 
            brand_cat="{embed:brand_cat}"
            type_cat="{category_id}"
            weblog="jewellery"
            brand_url="{segment_4}"
            cat_url_title="{category_url_title}"
            cat_name="{category_name}"}
    {/exp:weblog:categories}

    and the embedded template (.product_nav_list) looks like this:

    {exp:weblog:entries weblog="{embed:weblog}" category="{embed:brand_cat}&{embed:type_cat}" limit="1" dynamic="off"}
        <a href="/jewellery/products/cat/{embed:brand_url}/{embed:cat_url_title}">{embed:cat_name}</a>
    {/exp:weblog:entries}

    This probably doesn’t make sense in abstraction, but if it does make sense to anyone and they have some ideas I’d be so grateful to hear them!

  • #2 / Jan 30, 2011 11:21am

    Greg Salt

    3988 posts

    Hi Paul,

    Can you clarify; the weblog categories tag is in fact embedded from another tag? So, the weblog entries tag is a 3 deep embed? How many categories and entries do you have?

    Cheers

    Greg

  • #3 / Jan 31, 2011 6:45am

    Paul_B

    86 posts

    Hi Greg

    Thanks for getting back to me. The categories tag is part of another embed, yes. Essentially I’m using it to pull out the category id and url title for every category in the ‘type’ group, and then passing them to an embed to determine whether or not there are any entries of that jewellery type under the brand that the page is displaying. Does that make sense?

    Paul

  • #4 / Feb 01, 2011 2:47am

    John Henry Donovan

    12339 posts

    Paul,

    You would have enormous overhead with what you are doing. If you had say 30 categories returning that means essentially you are running the embedded weblog:entries tags 30 times.

    Take a look at this article. It is for EE2.x but a quick change of syntax would get it working in EE1.x. The theory is the same.

    Let us know if that helps

  • #5 / Feb 01, 2011 7:59am

    Paul_B

    86 posts

    Hi John

    Thanks very much for this. I love Low’s work and took to this idea straight away. I adapted it slightly to work for me, but I must have done something wrong because the page render time went from 1.6 seconds to 7.9 seconds :-(

    I had to up the weblog:entries limit to 500 as I’ve got a lot of products and the default setting of 100 wasn’t iterating through all of them.

    My code looked like this, which I think is right, but performance took a massive nosedive.

    {!-- <a href="http://loweblog.com/freelance/article/nesting-tags-and-performance-in-ee/">http://loweblog.com/freelance/article/nesting-tags-and-performance-in-ee/</a> --}
            <?php
              $entries = array();
              {exp:weblog:entries weblog="jewellery" disable="member_data|pagination|category_fields" limit="500"}
                $entry ={entry_id};
                {categories show_group="9"}
                  $entries[{category_id}][] = $entry;
                {/categories}
              {/exp:weblog:entries}
            ?>
            {exp:weblog:categories weblog="jewellery" category_group="9" style="linear" disable="category_fields"}
                {category_name}
              <?php if (isset($entries[{category_id}])): ?>
                  <li><a href="/jewellery/products/cat/{segment_4}/{category_url_title}">{category_name}</a></li>
              <?php endif; ?>
            {/exp:weblog:categories}

    Essentially I don’t need to output anything from the weblog:entries loop, I just need to take something so that I know there’s a product stored against that product type for that brand. So I just used the entry_id.

    If you can spot anything glaringly wrong with what I’ve done please feel free to tell me! Otherwise I might have to stick with what I’ve got - this is the last bit of inefficient code that I’m worried about, everything else I’ve streamlined and got the pages loading up to 10x faster in some places.

  • #6 / Feb 01, 2011 5:45pm

    Ingmar

    29245 posts

    I would definitely experiment with a custom SQL here. Can you tell us a little more about your data structure? Do you have one entry per piece of jewelry, with categories for both producer and type?

  • #7 / Feb 01, 2011 5:49pm

    Paul_B

    86 posts

    Hi Ingmar

    I have a weblog called jewellery, which has two category groups associated with it - jewellery brand and jewellery type. Each category group has about 10 categories in it (10 brands, 10 types)

    When I’m on a brand page, I only want to list jewellery non-empty jewellery types (brands have variable offerings, from very limited to very broad)

    Sounds simple when I write it out!

  • #8 / Feb 02, 2011 2:22pm

    Ingmar

    29245 posts

    Under that scenario, wouldn’t it make more sense to use related entries, perhaps? Use a separate channel for brands and relate the single jewelery entry to that brand. That way you could use (reverse) related entries easily. If you must use categories a custom SQL query is probably the most efficient way.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases