From 2d076504d9278e765f2e4bb27dc9fe2adfe2d370 Mon Sep 17 00:00:00 2001 From: Jeremy Kescher Date: Mon, 13 Mar 2023 22:34:28 +0100 Subject: [PATCH] Log what's causing the fetch_value errors. Port of https://github.com/mastodon/mastodon/issues/23644#issuecomment-1461863404 --- app/controllers/concerns/cache_concern.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/concerns/cache_concern.rb b/app/controllers/concerns/cache_concern.rb index 05e431b19a..fb4016f55f 100644 --- a/app/controllers/concerns/cache_concern.rb +++ b/app/controllers/concerns/cache_concern.rb @@ -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)