FEATURE: stop updating last_posted_at on users for messages and whispers

This ensures we only update last_posted_at which is user facing for non messages
and non whispers.

We still update this date for secure categories, we do not revert it for
deleted posts.
This commit is contained in:
Sam Saffron 2019-10-31 09:01:26 +11:00
parent fc06cfa90b
commit d8f7f363cd
3 changed files with 31 additions and 12 deletions

View File

@ -526,7 +526,9 @@ class PostCreator
@user.user_stat.save!
@user.update(last_posted_at: @post.created_at)
if !@topic.private_message? && @post.post_type != Post.types[:whisper]
@user.update(last_posted_at: @post.created_at)
end
end
def create_post_notice

View File

@ -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
)

View File

@ -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)