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.

Enormous performance penalty using {if} in {exp:query} when lots of rows

December 16, 2007 9:30am

Subscribe [2]
  • #1 / Dec 16, 2007 9:30am

    Patrick Savalle

    31 posts

    I noticed an gigantic performance penalty on using an {if} tag in a {exp:query} tags when the query returns a lot of rows (>2000).

    This code takes approx. 30secs. on our server:

    {exp:query sql="..."}
    {if total_results==0}
        ...
    {/if}
        ...
        <a href="/tag/channel/{tag_name}/{segment_3}">{tag_name} ({num})</a><br>
        ...
    {/exp:query}

    This code takes approx. 3 secs.

    {exp:query sql="..."}
        ...
        <a href="/tag/channel/{tag_name}/{segment_3}">{tag_name} ({num})</a><br>
        ...
    {/exp:query}

    This is the page in question:

    http://zaplog.nl/user/tag/ZapLog/ (without {if} -> 21 queries in 0.5430 s.)

    And here with the {if}

    http://zaplog.nl/user/tagg/ZapLog/ (with {if}, exactly the same chache-settings -> 23 queries in 33.9395 s.)

    Also, with this particular {if}-statement the page-caching will NOT work. Without the statement it does. Page loads in <0.5secs now instead of teh previous 30+ secs. 😊

    The query itself is very extensive but never takes >3 secs. when tested using a MySQL front-end.

  • #2 / Dec 16, 2007 10:17am

    Robin Sowell

    13255 posts

    Seems odd.  I’d start by putting just the query, nothing else, on a test template.  Turn ‘template debug’ on (Admin- System Prefs- Output and Debug) - run it with and w/out the conditional and compare the debug results.  Where is it tripping up on the second one?  Can you spot the lag point based on the debug?

    Also- I’d like to try to replicate, but it’s hard with custom queries where data doesn’t match up.  Does it fail the same on a really simple query like:

    {exp:query sql="SELECT title FROM exp_weblog_titles"}
    {title}
    {/exp:query}

    Well- when you put the conditional in there?  Does it slow it down?

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

ExpressionEngine News!

#eecms, #events, #releases