0

I have a Kohana 3.3 application, running on WAMP (PHP 5.4.3) which uses a static function to get a list of recent articles. When I load the page, the Application Execution time (via Kohana Profiler) is 6.7 seconds. When I load the same page without calling the get_recent method (passing an empty array) the Application Execution time is 0.3 seconds.

This indicates that this static method is causing a problem. I have run the raw MySQL and it takes 1.4 seconds.

This is the code inside the method:

$articles = self::factory('user_articles')
                ->join('articles', 'INNER')->on('user_articles.article_id', '=', 'articles.id')
                ->order_by('user_articles.created_at', 'ASC')
                ->limit(10)
                ->group_by('articles.id')->find_all();

There is an index on user_articles.article_id and on articles.id. Is there anything else I can do to optimize the query or speed up the execution time?

xylar
  • 7,433
  • 17
  • 55
  • 100

2 Answers2

0

You could add index on created_at - check with raw SQL if it helps or not.
It maybe also good idea not to use ORM and try to run a DB Builder query.

matino
  • 17,199
  • 8
  • 49
  • 58
0

Try to get last query by echo Database::instance()->last_query and try MySQL EXPLAIN. It will show you, which indexes are used.

PS: How many rows do you have in articles and users?

Mariyo
  • 486
  • 7
  • 15