From d696fdfa9ab94f73052d0806bfbdd76bd440c29c Mon Sep 17 00:00:00 2001 From: abram axel booth Date: Mon, 14 Oct 2024 10:52:04 -0400 Subject: [PATCH] fix: more consistent expulsion by suid --- share/admin/__init__.py | 4 +--- trove/digestive_tract.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/share/admin/__init__.py b/share/admin/__init__.py index 36ace6663..7d1b67a75 100644 --- a/share/admin/__init__.py +++ b/share/admin/__init__.py @@ -38,7 +38,6 @@ SourceUniqueIdentifier, ) from trove import digestive_tract -from trove.models import Indexcard class ShareAdminSite(admin.AdminSite): @@ -292,8 +291,7 @@ def reingest(self, request, queryset): def delete_cards_for_suid(self, request, queryset): for suid in queryset: FormattedMetadataRecord.objects.delete_formatted_records(suid) - for _indexcard in Indexcard.objects.filter(source_record_suid__in=queryset): - _indexcard.pls_delete() + digestive_tract.expel_suid(suid) def get_search_results(self, request, queryset, search_term): if not search_term: diff --git a/trove/digestive_tract.py b/trove/digestive_tract.py index 12888d394..7b78dcc00 100644 --- a/trove/digestive_tract.py +++ b/trove/digestive_tract.py @@ -202,12 +202,17 @@ def expel(from_user: share_db.ShareUser, record_identifier: str): source_config__source__user=from_user, identifier=record_identifier, ) + for _suid in _suid_qs: + expel_suid(_suid) + + +def expel_suid(suid: share_db.SourceUniqueIdentifier): ( trove_db.SupplementaryIndexcardRdf.objects - .filter(supplementary_suid__in=_suid_qs) + .filter(supplementary_suid=suid) .delete() ) - for _indexcard in trove_db.Indexcard.objects.filter(source_record_suid__in=_suid_qs): + for _indexcard in trove_db.Indexcard.objects.filter(source_record_suid=suid): _indexcard.pls_delete() @@ -222,8 +227,7 @@ def task__extract_and_derive(task: celery.Task, raw_id: int, urgent=False): ) _source_config = _raw.suid.source_config if _source_config.disabled or _source_config.source.is_deleted: - for _indexcard in trove_db.Indexcard.objects.filter(source_record_suid=_raw.suid): - _indexcard.pls_delete() + expel_suid(_raw.suid) else: if _raw.mediatype: _indexcards = extract(_raw, undelete_indexcards=urgent)