From 4002be2ea48fe06665eecf612a3d04ebe2685c0f Mon Sep 17 00:00:00 2001 From: Hironsan Date: Wed, 9 Aug 2023 14:57:24 +0900 Subject: [PATCH] Improve bulk assign performance --- backend/examples/assignment/usecase.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/examples/assignment/usecase.py b/backend/examples/assignment/usecase.py index 00408e48..f16949ea 100644 --- a/backend/examples/assignment/usecase.py +++ b/backend/examples/assignment/usecase.py @@ -14,8 +14,10 @@ def bulk_assign(project_id: int, strategy_name: StrategyName, member_ids: List[i raise ValueError("Invalid member ids") # Sort members by member_ids members = sorted(members, key=lambda m: member_ids.index(m.id)) + index_to_user = {i: member.user for i, member in enumerate(members)} unassigned_examples = Example.objects.filter(project=project, assignments__isnull=True) + index_to_example = {i: example for i, example in enumerate(unassigned_examples)} dataset_size = unassigned_examples.count() strategy = create_assignment_strategy(strategy_name, dataset_size, weights) @@ -23,8 +25,8 @@ def bulk_assign(project_id: int, strategy_name: StrategyName, member_ids: List[i assignments = [ Assignment( project=project, - example=unassigned_examples[assignment.example], - assignee=members[assignment.user].user, + example=index_to_example[assignment.example], + assignee=index_to_user[assignment.user], ) for assignment in assignments ]