FEATURE: unconditionally update Topic updated_at when posts change in topic

Previously we would bypass touching `Topic.updated_at` for whispers and post
recovery / deletions.

This meant that certain types of caching can not be done where we rely on
this information for cache accuracy.

For example if we know we have zero unread topics as of yesterday and whisper
is made I need to bump this date so the cache remains accurate

This is only half of a larger change but provides the groundwork.

Confirmed none of our serializers leak out Topic.updated_at so this is safe
spot for this info

At the moment edits still do not change this but it is not relevant for the
unread cache.

This commit also cleans up some specs to use the new `eq_time` matcher for
millisecond fidelity comparison of times

Previously `freeze_time` would fudge this which is not that clean.
This commit is contained in:
Sam Saffron
2019-03-28 17:28:01 +11:00
parent 5d134a6982
commit 9ebabc1de8
13 changed files with 96 additions and 15 deletions

View File

@ -419,16 +419,18 @@ class PostCreator
end
def update_topic_stats
attrs = { updated_at: Time.now }
if @post.post_type != Post.types[:whisper]
attrs = {}
attrs[:last_posted_at] = @post.created_at
attrs[:last_post_user_id] = @post.user_id
attrs[:word_count] = (@topic.word_count || 0) + @post.word_count
attrs[:excerpt] = @post.excerpt_for_topic if new_topic?
attrs[:bumped_at] = @post.created_at unless @post.no_bump
attrs[:updated_at] = Time.now
@topic.update_columns(attrs)
end
@topic.update_columns(attrs)
end
def update_topic_auto_close