Skip to content

Commit

Permalink
Ensure ids are mapped to str instead of UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincarrogan committed Nov 28, 2024
1 parent 2d97fec commit b2b23d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions api/cases/views/search/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,24 +272,24 @@ def populate_activity_updates(case_map):
"""
retrieve the last 2 activities per case for the provided list of cases
"""
case_ids = list(case_map.keys())
case_ids = list(str(pk) for pk in case_map.keys())
activities_qs = Audit.objects.get_latest_activities(case_ids, 2)
# get users data for activities en bulk to reduce query count
user_ids = {activity.actor_object_id for activity in activities_qs}
user_ids = {str(activity.actor_object_id) for activity in activities_qs}
users = BaseUser.objects.select_related("exporteruser", "govuser", "govuser__team").filter(id__in=user_ids)
user_map = {str(user.id): user for user in users}

for activity in activities_qs:
case_id = None
# get case id from either of the audit record fields
if activity.target_object_id in case_ids:
if str(activity.target_object_id) in case_ids:
case_id = activity.target_object_id
else:
case_id = activity.action_object_object_id
# prepopulate actor for AuditSerializer
actor = user_map[activity.actor_object_id]
actor = user_map[str(activity.actor_object_id)]
activity_obj = serialize_case_activity(activity, actor)
case = case_map[case_id]
case = case_map[str(case_id)]
if "activity_updates" in case:
case["activity_updates"].append(activity_obj)
else:
Expand Down
2 changes: 1 addition & 1 deletion api/cases/views/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get(self, request, *args, **kwargs):
case["advice"] = []
case["denials"] = []
case["goods"] = []
case_map[case["id"]] = case
case_map[str(case["id"])] = case
# Populate certain fields outside of the serializer for performance improvements
service.populate_goods_flags(cases)
service.populate_destinations_flags(cases)
Expand Down

0 comments on commit b2b23d8

Please sign in to comment.