mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-17 05:40:25 +00:00
Reduce calls to backend
Reading from an `ImageCacheFile`, will result in accessing its `file` attribute repeatedly which would result in the `before_access` signal being dispatched, which in turn would result in many unnecessary calls to the image cache backend. With this change, we don't send `before_access` if the file has already been created. Similarly, we don't need to try to generate the image if we know for certain that it's already been generated (because we have a reference to it).
This commit is contained in:
parent
bc49f9cf8b
commit
906fbbd463
1 changed files with 4 additions and 2 deletions
|
|
@ -56,7 +56,8 @@ class ImageCacheFile(BaseIKFile, ImageFile):
|
|||
super(ImageCacheFile, self).__init__(storage=storage)
|
||||
|
||||
def _require_file(self):
|
||||
before_access.send(sender=self, file=self)
|
||||
if not getattr(self, '_file', None):
|
||||
before_access.send(sender=self, file=self)
|
||||
|
||||
def generate(self, force=False):
|
||||
"""
|
||||
|
|
@ -64,7 +65,8 @@ class ImageCacheFile(BaseIKFile, ImageFile):
|
|||
whether the file already exists or not.
|
||||
|
||||
"""
|
||||
self.cachefile_backend.generate(self, force)
|
||||
if force or not getattr(self, '_file', None):
|
||||
self.cachefile_backend.generate(self, force)
|
||||
|
||||
def _generate(self):
|
||||
# Generate the file
|
||||
|
|
|
|||
Loading…
Reference in a new issue