Skip to content

Commit

Permalink
Optimize fetch_thumbnails (#3624)
Browse files Browse the repository at this point in the history
In case of a redis backend, this should prevent doing a redis pipeline that looks for a thumbnail
for image "" many times, for each empty image field (such as a member without profile picture).

Consider for example this (partial) redis pipeline call from sentry:

```
"HGETALL 'djthumbs:thumbnails:avatars/98a3dd0519bae43a2bfc45f2bb8653a0.jpg'",
"HGETALL 'djthumbs:thumbnails:'",
"HGETALL 'djthumbs:thumbnails:'",
"HGETALL 'djthumbs:thumbnails:avatars/1152ba8439c354c207967279fcbf4fcb.jpg'",
"HGETALL 'djthumbs:thumbnails:'",
// ... (45 more)
```
  • Loading branch information
DeD1rk authored Apr 10, 2024
1 parent 751bca9 commit 58edaf6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions website/utils/media/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def fetch_thumbnails(images: list, sizes=None):
:param sizes: A list of sizes to prefetch. If None, all sizes will be prefetched.
:return: None
"""
# Filter out empty ImageFieldFiles.
images = list(filter(bool, images))

if not images:
return

Expand Down

0 comments on commit 58edaf6

Please sign in to comment.