Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove additional queries looking for cached dimensions #501

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 14 additions & 11 deletions easy_thumbnails/files.py
Expand Up @@ -105,19 +105,22 @@ def database_get_image_dimensions(file, close=False, dimensions=None):
storage_hash = utils.get_storage_hash(file.storage)
dimensions = None
dimensions_cache = None
try:
thumbnail = models.Thumbnail.objects.select_related('dimensions').get(
storage_hash=storage_hash, name=file.name)
except models.Thumbnail.DoesNotExist:
thumbnail = None
else:
if settings.THUMBNAIL_CACHE_DIMENSIONS:
try:
dimensions_cache = thumbnail.dimensions
except models.ThumbnailDimensions.DoesNotExist:
dimensions_cache = None
if dimensions_cache:
return dimensions_cache.width, dimensions_cache.height
thumbnail = models.Thumbnail.objects.select_related('dimensions').get(
storage_hash=storage_hash, name=file.name)
except models.Thumbnail.DoesNotExist:
thumbnail = None
else:
try:
dimensions_cache = thumbnail.dimensions
except models.ThumbnailDimensions.DoesNotExist:
dimensions_cache = None
if dimensions_cache:
return dimensions_cache.width, dimensions_cache.height

dimensions = get_image_dimensions(file, close=close)

if settings.THUMBNAIL_CACHE_DIMENSIONS and thumbnail:
# Using get_or_create in case dimensions were created
# while running get_image_dimensions.
Expand Down