Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: stop updating last_posted_at on users for messages and whispers

Sam Saffrond8f7f363cd90
diff --git a/lib/post_creator.rb b/lib/post_creator.rb
index bb00ba335fb..1b41fef5aad 100644
--- a/lib/post_creator.rb
+++ b/lib/post_creator.rb
@@ -526,7 +526,9 @@ class PostCreator
@user.user_stat.save!
- @user.update(last_posted_at: @post.created_at)
+ if [email protected]_message? && @post.post_type != Post.types[:whisper]
+ @user.update(last_posted_at: @post.created_at)
+ end
end
def create_post_notice
diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake
index c0fbefed8f3..ca8fdc94866 100644
--- a/lib/tasks/import.rake
+++ b/lib/tasks/import.rake
@@ -384,12 +384,13 @@ end
def update_users
log "Updating users..."
- DB.exec <<-SQL
+ DB.exec(<<~SQL, Archetype.private_message)
WITH X AS (
- SELECT user_id
- , MIN(created_at) min_created_at
- , MAX(created_at) max_created_at
- FROM posts
+ SELECT p.user_id
+ , MIN(p.created_at) min_created_at
+ , MAX(p.created_at) max_created_at
+ FROM posts p
+ JOIN topics t ON t.id = p.topic_id AND t.archetype <> ?
WHERE deleted_at IS NULL
GROUP BY user_id
)
diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb
index c4decf5fa83..9dcb712723f 100644
--- a/spec/components/post_creator_spec.rb
+++ b/spec/components/post_creator_spec.rb
@@ -139,11 +139,10 @@ describe PostCreator do
cat.save
created_post = nil
- reply = nil
messages = MessageBus.track_publish do
created_post = PostCreator.new(admin, basic_topic_params.merge(category: cat.id)).create
- reply = PostCreator.new(admin, raw: "this is my test reply 123 testing", topic_id: created_post.topic_id).create
+ _reply = PostCreator.new(admin, raw: "this is my test reply 123 testing", topic_id: created_post.topic_id).create
end
# 2 for topic, one to notify of new topic another for tracking state
@@ -446,8 +445,8 @@ describe PostCreator do
end
it "creates missing tags if some exist" do
- existing_tag1 = Fabricate(:tag, name: tag_names[0])
- existing_tag1 = Fabricate(:tag, name: tag_names[1])
+ _existing_tag1 = Fabricate(:tag, name: tag_names[0])
+ _existing_tag1 = Fabricate(:tag, name: tag_names[1])
expect { @post = creator_with_tags.create }.to change { Tag.count }.by(tag_names.size - 2)
expect(@post.topic.tags.map(&:name).sort).to eq(tag_names.sort)
end
@@ -483,9 +482,16 @@ describe PostCreator do
fab!(:topic) { Fabricate(:topic, user: user) }
it 'whispers do not mess up the public view' do
- first = PostCreator.new(user,
+
+ freeze_time
+
+ first = PostCreator.new(
+ user,
topic_id: topic.id,
- raw: 'this is the first post').create
+ raw: 'this is the first post'
+ ).create
+
+ freeze_time 1.year.from_now
user_stat = user.user_stat
@@ -512,6 +518,9 @@ describe PostCreator do
expect(user_stat.reload.post_count).to eq(0)
+ user.reload
+ expect(user.last_posted_at).to eq_time(1.year.ago)
+
# date is not precise enough in db
whisper_reply.reload
@@ -742,6 +751,10 @@ describe PostCreator do
end
it 'acts correctly' do
+ freeze_time
+
+ user.update_columns(last_posted_at: 1.year.ago)
+
# It's not a warning
expect(post.topic.user_warning).to be_blank
@@ -760,6 +773,9 @@ describe PostCreator do
expect(post.user.user_stat.post_count).to eq(0)
expect(post.user.user_stat.topic_count).to eq(0)
+ user.reload
+ expect(user.last_posted_at).to eq_time(1.year.ago)
+
# archive this message and ensure archive is cleared for all users on reply
UserArchivedMessage.create(user_id: target_user2.id, topic_id: post.topic_id)