When get the sum of some objects: pluck.sum can be changed to sum()

app/models/trust_level3_requirements.rb:

user.user_visits.where('visited_at > ?', time_period.days.ago).pluck(:posts_read).sum
app/models/trust_level3_requirements.rb:    user.user_visits.pluck(:posts_read).sum

could be changed to

user.user_visits.where('visited_at > ?', time_period.days.ago).sum(:posts_read)
user.user_visits.sum(:posts_read)

since doing sum directly under db is faster than pluck and sum

3 Likes

Yeah, that sound right, @neil was there a reason for the “pull” and then “sum” stuff there?

There probably wasn’t a good reason for pluck and sum. /shrug

3 Likes

Hi, it looks like you are really interesting in development of Discourse. Mind also look for some advices here to tackle on the most intricate problems?

6 Likes

Thank you for the GitHub pull requests at https://github.com/discourse/discourse @junwen_yang! :hugs:

4 Likes