开发者

Codeigniter/Datamapper "where_related" causing too many queries

开发者 https://www.devze.com 2023-04-08 15:42 出处:网络
I have a many-to-many mapping between profiles and categories.This query: $profiles = new Profile(); $profiles->where(\'foobar_flag\',1);

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

精彩评论

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