FEATURE: show read time in last 60 days

This commit is contained in:
Neil Lalonde
2017-11-14 16:39:07 -05:00
parent c90c4b9703
commit b37e40eea9
15 changed files with 185 additions and 8 deletions

View File

@ -965,6 +965,12 @@ class User < ActiveRecord::Base
end
end
def recent_time_read
self.created_at && self.created_at < 60.days.ago ?
self.user_visits.where('visited_at >= ?', 60.days.ago).sum(:time_read) :
self.user_stat&.time_read
end
protected
def badge_grant

View File

@ -72,7 +72,9 @@ class UserStat < ActiveRecord::Base
if last_seen = last_seen_cached
diff = (Time.now.to_f - last_seen.to_f).round
if diff > 0 && diff < MAX_TIME_READ_DIFF
UserStat.where(user_id: id, time_read: time_read).update_all ["time_read = time_read + ?", diff]
update_args = ["time_read = time_read + ?", diff]
UserStat.where(user_id: id, time_read: time_read).update_all(update_args)
UserVisit.where(user_id: id, visited_at: Time.zone.now.to_date).update_all(update_args)
end
end
cache_last_seen(Time.now.to_f)

View File

@ -151,6 +151,10 @@ class UserSummary
.count
end
def recent_time_read
@user.recent_time_read
end
delegate :likes_given,
:likes_received,
:days_visited,