[英]Active Record Performance Issues
I have a rails application and I'm currently running into performance issues at scale. 我有一个Rails应用程序,目前正在大规模遇到性能问题。 I am using Rails 4 and MySQL for my backend.
我在后端使用Rails 4和MySQL。
I have a model named Coaches and I would like to group my response so that it only sends coaches with distinct emails. 我有一个名为Coaches的模型,我想对我的回答进行分组,以便它只向教练发送不同的电子邮件。
Here is an example: 这是一个例子:
Coach.group(:email)
However when i use this code with my production workload, it takes far too long to for Active Record to produce the result, see below. 但是,当我在生产工作负载中使用此代码时,Active Record生成结果所需的时间太长,请参见下文。
Coach Load (193743.7ms) SELECT `coaches`.* FROM `coaches` WHERE `coaches`.`deleted_at` IS NULL GROUP BY `coaches`.`email`
I have an index on the email and deleted_at column in my coaches table. 我在教练表中的email和delete_at列上都有一个索引。
Has anyone run into similar issues in the past? 过去有人遇到过类似问题吗?
您还需要在deleted_at
列上应用indexing
,并且一种合适的解决方案是使用分页(例如以限制格式使用数据)在这种情况下将为您提供帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.