【发布时间】:2014-04-17 20:28:03
【问题描述】:
在我的 rails 应用程序中,每个用户都有一个业力/分数,我通过用户模型计算如下:
after_invitation_accepted :increment_score_of_inviter
def increment_score_of_inviter
invitation_by.increment!(:score, 10)
end
def comment_vote_count
Vote.find(comment_ids).count * 2
end
def calculated_vote_count
base_score + comment_vote_count
end
def recalculate_score!
update_attribute(:score, calculated_vote_count)
end
我正在尝试创建所有用户的分页列表,按他们的分数排序。有成千上万的用户,我该如何有效地做到这一点?
我正在考虑使用:
User.all.sort_by(&:calculated_vote_count)
但是,这会很重。
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4