SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit d9888522 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Modify logic of delete_orphaned_attachment_file

parent a4cba341
No related branches found
No related tags found
No related merge requests found
......@@ -18,22 +18,14 @@ class Command(BaseCommand):
for att in sm.attachment_files.all()]
uuids_in_use = set(uuids_in_cm + uuids_in_sm)
print(uuids_in_use)
orphaned_att = AttachmentFile.objects.exclude(uuid__in=uuids_in_use)
print(orphaned_att)
for orphan_att in orphaned_att:
# We double-check that we're not deleting any used attachment
# since the 'exclude' logic above is risky
# (any mistake in uuids_in_use would lead to unwanted deletion)
try:
ComposedMessage.objects.filter(attachment_files__uuid=orphan_att.uuid).first()
except ComposedMessage.DoesNotExist:
try:
StoredMessage.objects.filter(attachment_files__uuid=orphan_att.uuid).first()
except StoredMessage.DoesNotExist:
if not ComposedMessage.objects.filter(attachment_files__uuid=orphan_att.uuid).exists():
if not StoredMessage.objects.filter(attachment_files__uuid=orphan_att.uuid).exists():
print('Deleting %s' % orphan_att.uuid)
if orphan_att.file:
if os.path.isfile(orphan_att.file.path):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment