Codeigniter/Datamapper“where_related”导致太多查询
我在个人资料
和类别
之间有一个多对多映射。此查询:
$profiles = new Profile();
$profiles->where('foobar_flag',1);
$profiles->where_related($category);
$profiles->get();
运行时间将近 30 秒,配置文件表中约有 1000 个条目。还有一个类别表和一个profiles_categories 表。每次执行我最终得到了惊人的 4000 个查询。
我怎样才能让它更快?
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 execution.
How do I make this faster?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您对 datamapper 中的功能不满意,请找到一种简化的方法来执行此操作,因为您的活动记录查询可能就像您所说的那样成本太高。
始终运行您的分析器:
这将使您真正了解幕后正在做什么。从那里开始优化。否则我们需要更多的代码来给出相关的答案。
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 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.