diff --git a/app/services/post_timestamp_changer.rb b/app/services/post_timestamp_changer.rb index 65b056128f9..2364c12472e 100644 --- a/app/services/post_timestamp_changer.rb +++ b/app/services/post_timestamp_changer.rb @@ -8,15 +8,19 @@ class PostTimestampChanger def change! ActiveRecord::Base.transaction do - update_topic + last_posted_at = @timestamp @posts.each do |post| if post.is_first_post? update_post(post, @timestamp) else - update_post(post, Time.at(post.created_at.to_f + @time_difference)) + new_created_at = Time.at(post.created_at.to_f + @time_difference) + last_posted_at = new_created_at if new_created_at > last_posted_at + update_post(post, new_created_at) end end + + update_topic(last_posted_at) end # Burst the cache for stats @@ -29,11 +33,12 @@ class PostTimestampChanger @timestamp - @topic.created_at end - def update_topic + def update_topic(last_posted_at) @topic.update_attributes( created_at: @timestamp, updated_at: @timestamp, - bumped_at: @timestamp + bumped_at: @timestamp, + last_posted_at: last_posted_at ) end diff --git a/spec/services/post_timestamp_changer_spec.rb b/spec/services/post_timestamp_changer_spec.rb index 03ec9a66445..245eaa3df97 100644 --- a/spec/services/post_timestamp_changer_spec.rb +++ b/spec/services/post_timestamp_changer_spec.rb @@ -21,6 +21,8 @@ describe PostTimestampChanger do [:created_at, :updated_at].each do |column| expect(p1.public_send(column)).to be_within_one_second_of(new_timestamp) end + + expect(topic.last_posted_at).to be_within_one_second_of(p2.reload.created_at) end describe 'predated timestamp' do