Skip to content

Commit

Permalink
Exclude reference refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Dec 12, 2024
1 parent 27e77ab commit 991dc66
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/collections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1322,8 +1322,8 @@ def get_ref_results(ref):

for reference in exclude_refs:
concepts, mappings = get_ref_results(reference)
index_concepts = self.__exclude_resources(reference, self.concepts, concepts)
index_mappings = self.__exclude_resources(reference, self.mappings, mappings)
index_concepts = self.__exclude_resources(reference, self.concepts, concepts, Concept)
index_mappings = self.__exclude_resources(reference, self.mappings, mappings, Mapping)

self.resolved_collection_versions.add(*compact(resolved_valueset_versions))
self.resolved_source_versions.add(*compact(resolved_system_versions))
Expand Down Expand Up @@ -1351,13 +1351,17 @@ def __include_resources(self, rel, resources, is_concept_queryset):
return should_index

@staticmethod
def __exclude_resources(ref, rel, resources):
def __exclude_resources(ref, rel, resources, klass):
should_index = resources.exists()
if should_index:
if ref.resource_version:
rel.remove(*resources)
else:
rel.set(rel.exclude(versioned_object_id__in=resources.values_list('versioned_object_id', flat=True)))
rel.remove(
*klass.objects.filter(
versioned_object_id__in=resources.values_list('versioned_object_id', flat=True)
)
)
return should_index

def index_resources(self, concepts, mappings):
Expand Down

0 comments on commit 991dc66

Please sign in to comment.