Skip to content

Commit

Permalink
Collection Reference Delete | Job to readd references to take less
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Feb 26, 2024
1 parent a67d5c4 commit 0f02b4d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
7 changes: 3 additions & 4 deletions core/collections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,13 +1078,12 @@ def delete_references(self, references):
self.index_mappings()

if any_ref_with_resources:
reference_ids_to_readd = self.collection_version.references.exclude(
id__in=[ref.id for ref in self.to_ref_list(references)]).values_list('id', flat=True)
removed_reference_ids = [ref.id for ref in self.to_ref_list(references)]
readd_task = readd_references_to_expansion_on_references_removal
if get(settings, 'TEST_MODE', False):
readd_task.apply_async((self.id, reference_ids_to_readd), queue='default')
readd_task(self.id, removed_reference_ids)
else:
readd_task(self.id, reference_ids_to_readd)
readd_task.apply_async((self.id, removed_reference_ids), queue='default')

def delete_expressions(self, expressions): # Deprecated: Old way, must use delete_references instead
concepts_filters = None
Expand Down
10 changes: 5 additions & 5 deletions core/common/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,9 @@ def calculate_checksums(resource_type, resource_id):


@app.task(ignore_result=True)
def readd_references_to_expansion_on_references_removal(expansion_id, reference_ids):
from core.collections.models import Expansion, CollectionReference
def readd_references_to_expansion_on_references_removal(expansion_id, removed_reference_ids):
from core.collections.models import Expansion
expansion = Expansion.objects.filter(id=expansion_id).first()
if expansion:
references = CollectionReference.objects.filter(id__in=reference_ids)
expansion.add_references(references, True, True, False)
if expansion and removed_reference_ids:
reference_to_readd = expansion.collection_version.references.exclude(id__in=removed_reference_ids)
expansion.add_references(reference_to_readd, True, True, False)

0 comments on commit 0f02b4d

Please sign in to comment.