范围:
scope :last_ten_minutes, -> { where('created_at > ?', Time.current - 10.minutes) }
scope :last_week, -> { where('created_at > ?', Time.current - 7.days) }
scope :last_hundred_days, -> { where('created_at > ?', Time.current - 100.days) }
数据库中大约有50万条这种模型的记录。它们经常与分页结合使用,但只能从管理面板中使用。
当然,这是减少时间的最佳方式。如果你有很多记录,并且会定期使用,那么你的问题的答案是肯定的,这是有意义的,也是可行的。