Update fetch_value logging patch

https://github.com/mastodon/mastodon/issues/23644#issuecomment-1461863404
This commit is contained in:
Jeremy Kescher 2023-03-14 10:27:21 +01:00
parent d092a01cea
commit b457636e9a
No known key found for this signature in database
GPG key ID: 48DFE4BB15BA5940

View file

@ -31,8 +31,11 @@ module CacheConcern
def cache_collection(raw, klass)
return raw unless klass.respond_to?(:with_includes)
begin
raw = raw.cache_ids.to_a if raw.is_a?(ActiveRecord::Relation)
raw = raw.cache_ids.to_a if raw.is_a?(ActiveRecord::Relation)
return [] if raw.empty?
cached_keys_with_value = begin
Rails.cache.read_multi(*raw).transform_keys(&:id)
rescue NoMethodError
culprit = raw.find do |item|
Rails.cache.read(item)
@ -41,17 +44,15 @@ module CacheConcern
true
end
Rails.logger.warn "fetch_value issue culprit: #{culprit.inspect}"
Rails.logger.warn "culprit: #{culprit.inspect}"
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))
Rails.logger.warn "base64 marshal of culprit: #{Base64.encode64(raw_marshal)}"
Rails.logger.warn "base64 marshal: #{Base64.encode64(raw_marshal)}"
raise
end
return [] if raw.empty?
cached_keys_with_value = Rails.cache.read_multi(*raw).transform_keys(&:id)
uncached_ids = raw.map(&:id) - cached_keys_with_value.keys
klass.reload_stale_associations!(cached_keys_with_value.values) if klass.respond_to?(:reload_stale_associations!)