Skip to content

Photo upload refactor#2733

Open
symroe wants to merge 7 commits into
masterfrom
photo-upload-refactor
Open

Photo upload refactor#2733
symroe wants to merge 7 commits into
masterfrom
photo-upload-refactor

Conversation

@symroe
Copy link
Copy Markdown
Member

@symroe symroe commented Apr 23, 2026

Move photo resizing and face detection to tasks.

I've used async_chain to split these up into two tasks, in case lumping them into one might case time outs or other issues.

@symroe symroe force-pushed the photo-upload-refactor branch from 37628a8 to 687453a Compare April 23, 2026 14:06
@symroe symroe force-pushed the photo-upload-refactor branch from 687453a to 1b08090 Compare April 23, 2026 14:14
@symroe symroe force-pushed the photo-upload-refactor branch from 1b08090 to 597b264 Compare April 23, 2026 15:26
@symroe symroe marked this pull request as ready for review April 23, 2026 15:27
@symroe symroe requested a review from chris48s April 23, 2026 15:27
Copy link
Copy Markdown
Member

@chris48s chris48s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not tried running this locally yet, but here's a few quick comments based on a scan over the diff

Comment thread ynr/apps/moderation_queue/models.py Outdated
Comment thread ynr/apps/moderation_queue/models.py Outdated
def start_image_processing(self):
from django_q.tasks import async_chain

async_chain(
Copy link
Copy Markdown
Member

@chris48s chris48s Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to explicitly set a timeout on these two tasks. Our default timeout for the cluster is 240 seconds. We need this to be quite long for our scheduled tasks which are processing many objects in a single run, but we should set a shorter timeout on these jobs that are only processing a single object.

Also a quick note on retries: Our cluster is set not to retry failed tasks. We basically need that to be true at the moment with all the tasks we have running on a short loop. We can't configure this at a task level, so if this fails once, it won't retry. I don't think that is a huge issue, but worth being aware of. Once we have fewer scheduled tasks running frequently, we can look at changing that. I think as it stands this is no worse than what we do now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this still stands

symroe added 3 commits April 27, 2026 15:41
Reduce the iterations to 12 not 20, close objects, remove alpha
and exif data.

All of this should help limit out of memory problems
# 15MB — Rekognition's S3 object size limit
MAX_IMAGE_BYTES = 15 * 1024 * 1024

def save_png_to_bytes(photo):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function save_png_to_bytes doesn't seem to be called anywhere

extension = filename.split(".")[-1]
filename = filename.replace(extension, "png")
self.image.save(filename, png_buffer, save=True)
sorl.thumbnail.delete(self.image.name, delete_file=False)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here where we clear the thumnail cache, self.image.name is now the new .png name so we're clearing the cache for the new .png name but not the old .jpg name. That seems unintended.

# RGBA rather than RGB so that any alpha channel (transparency)
# is preserved).

def strip_exifdata(photo):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not check this, but is this needed/doing anything?
I think as long as you call .save() witout explicitly passing the exif= arg that will strip the exif data on save.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants