From b9aff83d91e6e38ac331c0ba3624ad69bf07de21 Mon Sep 17 00:00:00 2001 From: Sunny Aggarwal Date: Fri, 31 Jul 2026 11:03:13 +0530 Subject: [PATCH] OpenConceptLab/ocl_issues#2657 | expansion concepts/mappings index on ref add should only index concept/mapping ids and not all versions of that concept/mapping --- core/collections/models.py | 24 ++++++++++++------------ core/common/tasks.py | 12 ++++++------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/core/collections/models.py b/core/collections/models.py index cc987c56..25e6e131 100644 --- a/core/collections/models.py +++ b/core/collections/models.py @@ -1303,11 +1303,11 @@ def apply_parameters(self, queryset, is_concept_queryset): parameters = ExpansionParameters(self.parameters, is_concept_queryset) return parameters.apply(queryset) - def index_concepts(self, concept_versioned_ids=None): - should_run = len(concept_versioned_ids) > 0 if concept_versioned_ids is not None else self.concepts.exists() + def index_concepts(self, concept_ids=None): + should_run = len(concept_ids) > 0 if concept_ids is not None else self.concepts.exists() if should_run: if get(settings, 'TEST_MODE', False): - index_expansion_concepts(self.id, self.concepts.count(), concept_versioned_ids) + index_expansion_concepts(self.id, self.concepts.count(), concept_ids) else: task = None try: @@ -1316,17 +1316,17 @@ def index_concepts(self, concept_versioned_ids=None): name=index_expansion_concepts.__name__ ) index_expansion_concepts.apply_async( - (self.id, self.concepts.count(), concept_versioned_ids), + (self.id, self.concepts.count(), concept_ids), task_id=task.id, queue=task.queue, persist_args=True) except AlreadyQueued: if task: task.delete() - def index_mappings(self, mapping_versioned_ids=None): - should_run = len(mapping_versioned_ids) > 0 if mapping_versioned_ids is not None else self.mappings.exists() + def index_mappings(self, mapping_ids=None): + should_run = len(mapping_ids) > 0 if mapping_ids is not None else self.mappings.exists() if should_run: if get(settings, 'TEST_MODE', False): - index_expansion_mappings(self.id, self.mappings.count(), mapping_versioned_ids) + index_expansion_mappings(self.id, self.mappings.count(), mapping_ids) else: task = None try: @@ -1335,7 +1335,7 @@ def index_mappings(self, mapping_versioned_ids=None): name=index_expansion_mappings.__name__ ) index_expansion_mappings.apply_async( - (self.id, self.mappings.count(), mapping_versioned_ids), + (self.id, self.mappings.count(), mapping_ids), task_id=task.id, queue=task.queue, persist_args=True) except AlreadyQueued: if task: @@ -1523,10 +1523,10 @@ def get_ref_results(ref): # pylint: disable=too-many-branches,too-many-locals concepts, mappings = get_ref_results(reference) concepts_updated = self.__include_resources(self.concepts, concepts, True) if index and concepts_updated is not False: - index_concepts = [*index_concepts, *concepts_updated.values_list('versioned_object_id', flat=True)] + index_concepts = [*index_concepts, *concepts_updated.values_list('id', flat=True)] mappings_updated = self.__include_resources(self.mappings, mappings, False) if index and mappings_updated is not False: - index_mappings = [*index_mappings, *mappings_updated.values_list('versioned_object_id', flat=True)] + index_mappings = [*index_mappings, *mappings_updated.values_list('id', flat=True)] for reference in exclude_refs: concepts, mappings = get_ref_results(reference) @@ -1535,14 +1535,14 @@ def get_ref_results(ref): # pylint: disable=too-many-branches,too-many-locals if index: if concepts_updated is not False: filters = { - 'versioned_object_id__in': list(concepts_updated.values_list('versioned_object_id', flat=True))} + 'id__in': list(concepts_updated.values_list('id', flat=True))} if get(settings, 'TEST_MODE', False): batch_index_resources('concept', filters) else: batch_index_resources.apply_async(('concept', filters), queue='indexing', permanent=False) if mappings_updated is not False: filters = { - 'versioned_object_id__in': list(mappings_updated.values_list('versioned_object_id', flat=True))} + 'id__in': list(mappings_updated.values_list('id', flat=True))} if get(settings, 'TEST_MODE', False): batch_index_resources('mapping', filters) else: diff --git a/core/common/tasks.py b/core/common/tasks.py index 85919345..23dcc70b 100644 --- a/core/common/tasks.py +++ b/core/common/tasks.py @@ -568,14 +568,14 @@ def batch_index_resources(resource, filters, update_indexed=False): ignore_result=True, autoretry_for=(Exception, WorkerLostError, ), retry_kwargs={'max_retries': 2, 'countdown': 2}, acks_late=True, reject_on_worker_lost=True, base=QueueOnceCustomTask ) -def index_expansion_concepts(expansion_id, count=None, concept_versioned_ids=None): # pylint: disable=unused-argument +def index_expansion_concepts(expansion_id, count=None, concept_ids=None): # pylint: disable=unused-argument from core.collections.models import Expansion expansion = Expansion.objects.filter(id=expansion_id).first() if expansion: from core.concepts.documents import ConceptDocument from core.concepts.models import Concept - if concept_versioned_ids: - queryset = Concept.objects.filter(versioned_object_id__in=concept_versioned_ids) + if concept_ids: + queryset = Concept.objects.filter(id__in=concept_ids) else: queryset = expansion.concepts expansion.batch_index( @@ -589,14 +589,14 @@ def index_expansion_concepts(expansion_id, count=None, concept_versioned_ids=Non ignore_result=True, autoretry_for=(Exception, WorkerLostError, ), retry_kwargs={'max_retries': 2, 'countdown': 2}, acks_late=True, reject_on_worker_lost=True, base=QueueOnceCustomTask ) -def index_expansion_mappings(expansion_id, count=None, mapping_versioned_ids=None): # pylint: disable=unused-argument +def index_expansion_mappings(expansion_id, count=None, mapping_ids=None): # pylint: disable=unused-argument from core.collections.models import Expansion expansion = Expansion.objects.filter(id=expansion_id).first() if expansion: from core.mappings.documents import MappingDocument from core.mappings.models import Mapping - if mapping_versioned_ids: - queryset = Mapping.objects.filter(versioned_object_id__in=mapping_versioned_ids) + if mapping_ids: + queryset = Mapping.objects.filter(id__in=mapping_ids) else: queryset = expansion.mappings expansion.batch_index(