Kaynağa Gözat

Update find_existing_rendition() to utilise find_existing_renditions() (this is fine because these methods are self-contained)

Andy Babic 2 yıl önce
ebeveyn
işleme
0f84c66363
1 değiştirilmiş dosya ile 3 ekleme ve 25 silme
  1. 3 25
      wagtail/images/models.py

+ 3 - 25
wagtail/images/models.py

@@ -473,35 +473,13 @@ class AbstractImage(ImageFileMixin, CollectionMember, index.Indexed, models.Mode
         Note: If using custom image models, an instance of the custom rendition
         model will be returned.
         """
-
         Rendition = self.get_rendition_model()
-        cache_key = filter.get_cache_key(self)
-
-        # Interrogate prefetched values first (if available)
-        prefetched_renditions = self._get_prefetched_renditions()
-        if prefetched_renditions is not None:
-            for rendition in prefetched_renditions:
-                if (
-                    rendition.filter_spec == filter.spec
-                    and rendition.focal_point_key == cache_key
-                ):
-                    return rendition
 
-            # If renditions were prefetched, assume that if a suitable match
-            # existed, it would have been present and already returned above
-            # (avoiding further cache/db lookups)
+        try:
+            return self.find_existing_renditions(filter)[filter]
+        except KeyError:
             raise Rendition.DoesNotExist
 
-        # Next, query the cache (if configured)
-        if self.renditions_cache is not None:
-            key = Rendition.construct_cache_key(self.id, cache_key, filter.spec)
-            cached_rendition = self.renditions_cache.get(key)
-            if cached_rendition:
-                return cached_rendition
-
-        # Resort to a get() lookup
-        return self.renditions.get(filter_spec=filter.spec, focal_point_key=cache_key)
-
     def create_rendition(self, filter: "Filter") -> "AbstractRendition":
         """
         Creates and returns a ``Rendition`` instance with a ``file`` field