FEATURE: Add `new_since` column to `UserStat` so we can reset the "New"
date.
This commit is contained in:
parent
5c3f2feed4
commit
3abe84941f
|
@ -84,8 +84,8 @@ class TopicTrackingState
|
|||
|
||||
def self.treat_as_new_topic_clause
|
||||
User.where("CASE
|
||||
WHEN COALESCE(u.new_topic_duration_minutes, :default_duration) = :always THEN u.created_at
|
||||
WHEN COALESCE(u.new_topic_duration_minutes, :default_duration) = :last_visit THEN COALESCE(u.previous_visit_at,u.created_at)
|
||||
WHEN COALESCE(u.new_topic_duration_minutes, :default_duration) = :always THEN us.new_since
|
||||
WHEN COALESCE(u.new_topic_duration_minutes, :default_duration) = :last_visit THEN COALESCE(u.previous_visit_at,us.new_since)
|
||||
ELSE (:now::timestamp - INTERVAL '1 MINUTE' * COALESCE(u.new_topic_duration_minutes, :default_duration))
|
||||
END",
|
||||
now: DateTime.now,
|
||||
|
@ -119,6 +119,7 @@ class TopicTrackingState
|
|||
c.name AS category_name,
|
||||
tu.notification_level
|
||||
FROM users u
|
||||
INNER JOIN user_stats AS us ON us.user_id = u.id
|
||||
FULL OUTER JOIN topics ON 1=1
|
||||
LEFT JOIN topic_users tu ON tu.topic_id = topics.id AND tu.user_id = u.id
|
||||
LEFT JOIN categories c ON c.id = topics.category_id
|
||||
|
|
|
@ -466,9 +466,9 @@ class User < ActiveRecord::Base
|
|||
duration = new_topic_duration_minutes || SiteSetting.new_topic_duration_minutes
|
||||
case duration
|
||||
when User::NewTopicDuration::ALWAYS
|
||||
created_at
|
||||
user_stat.new_since
|
||||
when User::NewTopicDuration::LAST_VISIT
|
||||
previous_visit_at || created_at
|
||||
previous_visit_at || user_stat.new_since
|
||||
else
|
||||
duration.minutes.ago
|
||||
end
|
||||
|
@ -563,7 +563,7 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def create_user_stat
|
||||
stat = UserStat.new
|
||||
stat = UserStat.new(new_since: Time.now)
|
||||
stat.user_id = id
|
||||
stat.save!
|
||||
end
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class AddNewSinceToUserStats < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :user_stats, :new_since, :datetime
|
||||
execute "UPDATE user_stats AS us
|
||||
SET new_since = u.created_at
|
||||
FROM users AS u
|
||||
WHERE u.id = us.user_id"
|
||||
change_column :user_stats, :new_since, :datetime, null: false
|
||||
end
|
||||
end
|
|
@ -7,6 +7,9 @@ describe UserStat do
|
|||
it "is created automatically when a user is created" do
|
||||
user = Fabricate(:evil_trout)
|
||||
user.user_stat.should be_present
|
||||
|
||||
# It populates the `new_since` field by default
|
||||
user.user_stat.new_since.should be_present
|
||||
end
|
||||
|
||||
context '#update_view_counts' do
|
||||
|
|
Loading…
Reference in New Issue