Skip to content

Commit

Permalink
perf: uses pagination for las (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtyoung84 authored Jul 15, 2024
1 parent 5a0a9dc commit 83ef624
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/aind_metadata_service/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
LabTracksClient,
LabTracksSettings,
)

from aind_metadata_service.response_handler import EtlResponse
from aind_metadata_service.sharepoint.client import (
SharePointClient,
Expand Down
8 changes: 4 additions & 4 deletions src/aind_metadata_service/sharepoint/las2020/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
from datetime import date, datetime
from decimal import Decimal, DecimalException
from enum import Enum
from typing import Any, Optional, List
from typing import Any, List, Optional

from aind_data_schema.core.procedures import (
Surgery,
Side,
IntraperitonealInjection,
RetroOrbitalInjection,
Side,
Surgery,
ViralMaterial,
)

from aind_metadata_service.sharepoint.las2020.models import (
LASList,
Doseroute,
LASList,
Rosop,
)

Expand Down
26 changes: 15 additions & 11 deletions src/aind_metadata_service/sharepoint/las2020/procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,22 @@ def get_procedures_from_sharepoint(
-------
List[SubjectProcedure]
"""
labtrack_alias = LASList.model_fields.get("title").alias
filter_string = f"substringof('{subject_id}', {labtrack_alias})"
title_alias = LASList.model_fields.get("title").alias
filter_string = f"substringof('{subject_id}', {title_alias})"
list_view = client_context.web.lists.get_by_title(list_title)
client_context.load(list_view)
client_context.execute_query()
list_items = list_view.get_items().filter(filter_string)
client_context.load(list_items)
client_context.execute_query()
list_items = (
list_view.items.paged(True)
.top(100)
.get()
.filter(filter_string)
.execute_query()
)
list_of_procedures = []
for list_item in list_items:
las_model = LASList.model_validate(list_item.to_json())
mapped_model = MappedLASList(las=las_model)
procedure = mapped_model.get_procedure(subject_id=subject_id)
list_of_procedures.append(procedure)
list_item_json = list_item.to_json()
if subject_id in list_item_json[title_alias].split(" "):
las_model = LASList.model_validate(list_item.to_json())
mapped_model = MappedLASList(las=las_model)
procedure = mapped_model.get_procedure(subject_id=subject_id)
list_of_procedures.append(procedure)
return list_of_procedures
15 changes: 11 additions & 4 deletions tests/sharepoint/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,21 @@ def test_las_data_mapped(self, mock_sharepoint_client: MagicMock):
)
mock_list_view = MagicMock()
inner_mock.web.lists.get_by_title.return_value = mock_list_view
mock_list_items = MagicMock()
mock_list_view.get_items.return_value = mock_list_items
mock_l_items = MagicMock()

list_item_2020_1 = self.list_items_2020[0][0]
mock_list_item2020 = MagicMock()
mock_list_item2020.to_json.return_value = list_item_2020_1
mock_list_items.filter.side_effect = [

mock_get = MagicMock()
mock_l_items.paged.return_value.top.return_value.get.return_value = (
mock_get
)

mock_get.filter.return_value.execute_query.side_effect = [
[mock_list_item2020],
]
mock_list_view.items = mock_l_items

client = SharePointClient(
nsb_site_url="some_url",
Expand All @@ -282,7 +289,7 @@ def test_las_data_mapped(self, mock_sharepoint_client: MagicMock):
)
expected_subject_procedures = [self.list_items_2020[0][1]]
response2020 = client.get_procedure_info(
subject_id="12345", list_title="some_list_title2020"
subject_id="000000", list_title="some_list_title2020"
)
json_response = response2020.map_to_json_response()
actual_content = json.loads(json_response.body.decode("utf-8"))
Expand Down

0 comments on commit 83ef624

Please sign in to comment.