Skip to content
Permalink
Browse files

posts: fix members not being able to tag posts.

Fix regression caused by 3d3f615. This is what happened:

* The posts controller calls post.visible? before post.update.
* post.visible? calls post.tag_array.
* The call to tag_array causes the current value of tag_string to be
  cached in @tag_array.
* post.update calls post.merge_old_changes.
* post.merge_old_changes accesses tag_array, which contains the old
  cached version of tag_string rather than the new version from the
  update.
* post.merge_old_changes detects no changes, so the update does nothing.
* This only happens for Members because for Gold+ users the call to
  post.visible? short circuits before accessing tag_array.

Moral of the story: cache invalidation is hard. Don't cache unless you have to.
  • Loading branch information
evazion committed Jan 10, 2020
1 parent 2cf0e7d commit fc06a2a0f76e212ac5dc1c311cea3229a3b1f613
Showing with 1 addition and 0 deletions.
  1. +1 −0 app/models/post.rb
@@ -589,6 +589,7 @@ def set_tag_counts(disable_cache = true)
end

def merge_old_changes
reset_tag_array_cache
@removed_tags = []

if old_tag_string

0 comments on commit fc06a2a

Please sign in to comment.
You can’t perform that action at this time.