From fc06a2a0f76e212ac5dc1c311cea3229a3b1f613 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 9 Jan 2020 18:54:03 -0600 Subject: [PATCH] posts: fix members not being able to tag posts. Fix regression caused by 3d3f61559. 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. --- app/models/post.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/post.rb b/app/models/post.rb index 29645eb87..97dd5d7f9 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -589,6 +589,7 @@ class Post < ApplicationRecord end def merge_old_changes + reset_tag_array_cache @removed_tags = [] if old_tag_string