lib/wcc/contentful/middleware/store/caching_middleware.rb in wcc-contentful-1.2.0 vs lib/wcc/contentful/middleware/store/caching_middleware.rb in wcc-contentful-1.2.1
- old
+ new
@@ -34,16 +34,12 @@
# TODO: https://github.com/watermarkchurch/wcc-contentful/issues/18
# figure out how to cache the results of a find_by query, ex:
# `find_by('slug' => '/about')`
def find_by(content_type:, filter: nil, options: nil)
- if filter&.keys == ['sys.id']
- # Direct ID lookup, like what we do in `WCC::Contentful::ModelMethods.resolve`
- # We can return just this item. Stores are not required to implement :include option.
- if found = @cache.read(filter['sys.id'])
- return found
- end
+ if filter&.keys == ['sys.id'] && found = @cache.read(filter['sys.id'])
+ return found
end
store.find_by(content_type: content_type, filter: filter, options: options)
end
@@ -77,11 +73,11 @@
id = json.dig('sys', 'id')
type = json.dig('sys', 'type')
prev = @cache.read(id)
return if prev.nil? && LAZILY_CACHEABLE_TYPES.include?(type)
- if (prev_rev = prev&.dig('sys', 'revision')) && (next_rev = json.dig('sys', 'revision'))
- return prev if next_rev < prev_rev
+ if (prev_rev = prev&.dig('sys', 'revision')) && (next_rev = json.dig('sys', 'revision')) && (next_rev < prev_rev)
+ return prev
end
# we also set DeletedEntry objects in the cache - no need to go hit the API when we know
# this is a nil object
@cache.write(id, json, expires_in: expires_in)