Log what's causing the fetch_value errors.

Port of https://github.com/mastodon/mastodon/issues/23644#issuecomment-1461863404
This commit is contained in:
Jeremy Kescher 2023-03-13 22:34:28 +01:00
parent 3158b0ac17
commit 2d076504d9
No known key found for this signature in database
GPG key ID: 48DFE4BB15BA5940

View file

@ -31,7 +31,24 @@ module CacheConcern
def cache_collection(raw, klass)
return raw unless klass.respond_to?(:with_includes)
raw = raw.cache_ids.to_a if raw.is_a?(ActiveRecord::Relation)
begin
raw = raw.cache_ids.to_a if raw.is_a?(ActiveRecord::Relation)
rescue NoMethodError
culprit = raw.find do |item|
Rails.cache.read(item)
false
rescue NoMethodError
true
end
$stderr.puts "fetch_value issue culprit: #{culprit.inspect}\n"
cache_key = Rails.cache.send(:normalize_key, culprit, {})
entry = Rails.cache.send(:read_entry, cache_key)
raw_marshal = Zlib::Inflate.inflate(entry.instance_variable_get(:@value))
$stderr.puts "base64 marshal of culprit: #{Base64.encode64(raw_marshal)}"
end
return [] if raw.empty?
cached_keys_with_value = Rails.cache.read_multi(*raw).transform_keys(&:id)