Skip to content

Commit

Permalink
OpenConceptLab/ocl_issues#1417 Fix FHIR global space loading time
Browse files Browse the repository at this point in the history
  • Loading branch information
rkorytkowski committed Jan 26, 2023
1 parent 0e1b5dd commit 4c5ee31
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion core/code_systems/serializers.py
Expand Up @@ -138,7 +138,11 @@ def to_internal_value(self, data):
def to_representation(self, value):
# limit to 1000 concepts by default
# TODO: support graphQL to go around the limit
return CodeSystemConceptSerializer(value.concepts.order_by('id')[:1000], many=True).data
if self.context.get('has_many', False):
limit = 25
else:
limit = 1000
return CodeSystemConceptSerializer(value.concepts.order_by('id')[:limit], many=True).data


class CodeSystemDetailSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -173,6 +177,14 @@ class Meta:
'copyright', 'revisionDate', 'experimental', 'caseSensitive', 'compositional', 'versionNeeded',
'collectionReference', 'hierarchyMeaning', 'concept', 'text')

def __new__(cls, *args, **kwargs):
if kwargs.get('many', False):
context = kwargs.get('context', {})
context.update({'has_many': True})
kwargs.update({'context': context})

return super().__new__(cls, *args, **kwargs)

@staticmethod
def get_resource_type(_):
return RESOURCE_TYPE
Expand Down
14 changes: 13 additions & 1 deletion core/concept_maps/serializers.py
Expand Up @@ -45,7 +45,11 @@ def to_internal_value(self, data):
def to_representation(self, value):
# limit to 1000 mappings by default
# TODO: support graphQL to go around the limit
mappings = value.get_mappings_queryset().order_by('id')[:1000]
if self.context.get('has_many', False):
limit = 25
else:
limit = 1000
mappings = value.get_mappings_queryset().order_by('id')[:limit]
groups = {}
for mapping in mappings:
key = mapping.from_source_url + mapping.to_source_url
Expand Down Expand Up @@ -110,6 +114,14 @@ class Meta:
'version', 'identifier', 'contact', 'jurisdiction', 'name', 'description', 'publisher', 'purpose',
'copyright', 'date', 'experimental', 'group')

def __new__(cls, *args, **kwargs):
if kwargs.get('many', False):
context = kwargs.get('context', {})
context.update({'has_many': True})
kwargs.update({'context': context})

return super().__new__(cls, *args, **kwargs)

@staticmethod
def get_resource_type(_):
return RESOURCE_TYPE
Expand Down

0 comments on commit 4c5ee31

Please sign in to comment.