Jump to content
rjgamer

Boost up count queries

Recommended Posts

Hi,

how can I boost up this code in my template?

<?php $selector = 'template=game, genre.name=strategy'; ?>
<?php foreach ($topics as $topic): ?> <!-- ~50 topics -->
	<?php $count = pages()->count($selector . ', topics.name=' . $topic->name) ?><!-- more than 1000 games -->
    	<!-- My awesome super stuff with $count -->
<?php endforeach ?>

I've three similar queries of the code above in a template and it slows down the page load ~2secs. How can I boost up the count query?

Thanks

Share this post


Link to post
Share on other sites

how.abt u use $cache 2 do jus do it. 1once per hour ?

echo $cache->get('topic-count', 3600, function() use($topics) {
  $str = '';
  $strategy = pages()->get("template=genre, name=strategy");
  foreach($topics as $topic) {
    $count = pages()->count("template=game, genre=$strategy, topic=$topic");
    $str .= "<li>$topic->title: $count games</li>";
  }
  return $str;
}); 

also.2 make faster u better should uses "id" not name, so "topics" no 'topics.name' and "genre" not genre.name etc. othrwis pw have to look those up for u (?) every time of foreach

@rjgamer

  • Like 2

Share this post


Link to post
Share on other sites

Thank you. It looks like that to cache the HTML output is the only solution.

Strange is, that the cache offers a renderFile method. But I dont get it to work to render a partial (site/templates/partials/foo/bar.php). Does anybody have a working example?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...