Skip to content

Commit

Permalink
feat: improve ontology performance
Browse files Browse the repository at this point in the history
  • Loading branch information
JackScanlon committed Jan 15, 2025
1 parent 08199ed commit c7fb9cf
Show file tree
Hide file tree
Showing 11 changed files with 786 additions and 297 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def get_generic_entities(request):

groups = list(user.groups.all().values_list('id', flat=True))
if len(groups) > 0:
group_ids = [ gen_utils.parse_int(group) for group in groups ]
group_ids = [ int(group) for group in groups if gen_utils.parse_int(group, default=None) ]
user_clause = f'''{user_clause} or (entity.group_id = any(%(group_ids)s) and entity.group_access = any(array[2, 3]))'''

accessible_clauses.append(f'({user_clause})')
Expand Down
4 changes: 2 additions & 2 deletions CodeListLibrary_project/clinicalcode/api/views/Ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@api_view(['GET'])
@permission_classes([IsAuthenticatedOrReadOnly])
@cache_page(60 * 60 * 2)
@cache_page(60 * 60 * 8)
def get_ontologies(request):
"""
Get all ontology groups and their root
Expand All @@ -29,7 +29,7 @@ def get_ontologies(request):

@api_view(['GET'])
@permission_classes([IsAuthenticatedOrReadOnly])
@cache_page(60 * 60 * 2)
@cache_page(60 * 60 * 8)
def get_ontology_detail(request, ontology_id):
"""
Get specified ontology group type detail by the given `ontology_id`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def build_template_subquery_from_string(param, data, top_ref, sub_ref, validatio
ltype = '::bigint'
datatype = '::bigint'
elif sub_type == 'string_array':
data = [ str(x).lower() for x in data.split(',') if gen_utils.try_value_as_type(x, 'string') ]
data = [ str(x).lower() for x in data.split(',') if gen_utils.try_value_as_type(x, 'string') is not None ]
ltype = '::text'
datatype = ''
processor = 'lower'
Expand Down Expand Up @@ -520,7 +520,7 @@ def build_template_subquery_from_string(param, data, top_ref, sub_ref, validatio
data = [ int(x) for x in data.split(',') if isinstance(gen_utils.parse_int(x, default=None), int) ]
datatype = 'bigint'
elif sub_type == 'string_array':
data = [ str(x).lower() for x in data.split(',') if gen_utils.try_value_as_type(x, 'string') ]
data = [ str(x).lower() for x in data.split(',') if gen_utils.try_value_as_type(x, 'string') is not None ]
datatype = 'text'
processor = 'lower'

Expand Down Expand Up @@ -651,7 +651,7 @@ def build_query_string_from_param(param, data, validation, field_type, is_dynami
source = validation.get('source')
trees = source.get('trees') if source and 'trees' in validation.get('source') else None
if trees:
data = [ str(x) for x in data.split(',') if gen_utils.try_value_as_type(x, 'string') ]
data = [ str(x) for x in data.split(',') if gen_utils.try_value_as_type(x, 'string') is not None ]
model = source.get('model') if isinstance(source.get('model'), str) else None

if model:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def get_concept_headers(concept_information, default=None):
columns = [col[0] for col in cursor.description]
results = [dict(zip(columns, row)) for row in cursor.fetchall()]

if len(results) < 0:
if len(results) < 1:
return default

return results
Expand Down Expand Up @@ -377,7 +377,7 @@ def get_concept_dataset(packet, field_name='concept_information', default=None):
columns = [col[0] for col in cursor.description]
results = [dict(zip(columns, row)) for row in cursor.fetchall()]

if len(results) < 0:
if len(results) < 1:
return default

return results
Expand Down
Loading

0 comments on commit c7fb9cf

Please sign in to comment.