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.rbindex 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)+ endenddef create_post_noticediff --git a/lib/tasks/import.rake b/lib/tasks/import.rakeindex c0fbefed8f3..ca8fdc94866 100644--- a/lib/tasks/import.rake+++ b/lib/tasks/import.rake@@ -384,12 +384,13 @@ enddef update_userslog "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 NULLGROUP BY user_id)diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rbindex c4decf5fa83..9dcb712723f 100644--- a/spec/components/post_creator_spec.rb+++ b/spec/components/post_creator_spec.rb@@ -139,11 +139,10 @@ describe PostCreator docat.savecreated_post = nil- reply = nilmessages = MessageBus.track_publish docreated_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).createend# 2 for topic, one to notify of new topic another for tracking state@@ -446,8 +445,8 @@ describe PostCreator doendit "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 dofab!(: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_nowuser_stat = user.user_stat@@ -512,6 +518,9 @@ describe PostCreator doexpect(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 dbwhisper_reply.reload@@ -742,6 +751,10 @@ describe PostCreator doendit 'acts correctly' do+ freeze_time++ user.update_columns(last_posted_at: 1.year.ago)+# It's not a warningexpect(post.topic.user_warning).to be_blank@@ -760,6 +773,9 @@ describe PostCreator doexpect(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 replyUserArchivedMessage.create(user_id: target_user2.id, topic_id: post.topic_id)