Skip to content

Commit

Permalink
Fix Rails cache namespace being overriden with v2 for cached statuses
Browse files Browse the repository at this point in the history
Follow-up to mastodon#24142
  • Loading branch information
ClearlyClaire committed Mar 21, 2023
1 parent 38c84f5 commit 56cb674
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/concerns/cache_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def cache_collection(raw, klass)
return [] if raw.empty?

cached_keys_with_value = begin
Rails.cache.read_multi(*raw, namespace: 'v2').transform_keys(&:id).transform_values { |r| ActiveRecordCoder.load(r) }
Rails.cache.read_multi(*raw).transform_keys(&:id).transform_values { |r| ActiveRecordCoder.load(r) }
rescue ActiveRecordCoder::Error
{} # The serialization format may have changed, let's pretend it's a cache miss.
end
Expand All @@ -200,7 +200,7 @@ def cache_collection(raw, klass)
uncached = klass.where(id: uncached_ids).with_includes.index_by(&:id)

uncached.each_value do |item|
Rails.cache.write(item, ActiveRecordCoder.dump(item), namespace: 'v2')
Rails.cache.write(item, ActiveRecordCoder.dump(item))
end
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ class Status < ApplicationRecord

REAL_TIME_WINDOW = 6.hours

def cache_key
"v2:#{super}"
end

def searchable_by(preloaded = nil)
ids = []

Expand Down

0 comments on commit 56cb674

Please sign in to comment.