Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rails cache namespace being overriden with v2 for cached statuses #24202

Merged
merged 1 commit into from Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/concerns/cache_concern.rb
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
Expand Up @@ -29,7 +29,7 @@
# ordered_media_attachment_ids :bigint(8) is an Array
#

class Status < ApplicationRecord

Check failure on line 32 in app/models/status.rb

View workflow job for this annotation

GitHub Actions / lint

Metrics/ClassLength: Class has too many lines. [376/375]
before_destroy :unlink_from_conversations!

include Discard::Model
Expand Down Expand Up @@ -140,6 +140,10 @@

REAL_TIME_WINDOW = 6.hours

def cache_key
"v2:#{super}"
end

def searchable_by(preloaded = nil)
ids = []

Expand Down