开发者

Codeigniter/Datamapper "where_related" causing too many queries

I have a many-to-many mapping between profiles and categories. This query:

$profiles = new Profile();  
$profiles->where('foobar_flag',1);
$profiles->where_related($category);
$profiles->get();

Is taking almost 30 seconds to run, with about 1000 entries in that profiles table. There is also a category table, and a profiles_categories table. I end up with a staggering 4000 queries per e开发者_开发百科xecution.

How do I make this faster?


If you are unhappy with a function in datamapper, either find a simplified way of doing it as your active record query might just be too costly as you say.

Always run your profiler:

$this->output->enable_profiler(TRUE);

This will give you a true idea of what is being done behind the scenes. Optimize from there on. Otherwise we need more code to go on here to give relevant answers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜