[英]How to scan the whole table contains the millions of records to return last month or last year records in Ruby on Rails
I am the beginner in rails and facing following performance issues, guidance will be appreciated: Wanted to show daily & monthly user registrations on flot graph for the specific outlet. 我是Rails的初学者,并且遇到以下性能问题,我们将为您提供指导:希望在特定网点的图表上显示每日和每月的用户注册。 How can I print this on dashboard ?
如何在仪表板上打印此内容? =>
=>
To get the users who are registered in the last month (for daily) or last year (for monthly), I need to scan whole table of size more than 10,00,000 records, which is time consuming & nginx gives 502 error. 为了获得在上个月(每天)或去年(每月)注册的用户,我需要扫描整个表,其大小超过10,00,000条记录,这非常耗时,nginx会显示502错误。
User & Outlet model doesn't have any association. 用户与插座模型没有任何关联。
User contains the field outlet_code which is unique in outlet table 用户包含在插座表中唯一的字段outlet_code
Users registered in last 12 months: 最近12个月内注册的用户:
@users = User.where('created_at >= ?', Date.today - 12.months)
Users registered in last 30 days: 最近30天内注册的用户:
@users = User.where('created_at >= ?', Date.today - 30.days)
Users registered in last day: 前一天注册的用户:
@users = User.where('created_at >= ?', Date.today - 24.hours)
Users registered this year: 今年注册的用户:
@users = User.where('created_at >= ?', Date.today.year)
Users registered this month: 本月注册的用户:
@users = User.where('created_at >= ?', Date.today.month)
Users registered today: 今天注册的用户:
@users = User.where('created_at >= ?', Date.today)
Example of how to render: 如何渲染的示例:
<% @users.each do |user| %>
<%= user.outlet_code %><br><br>
<% end %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.