Browse Source

Improve bulk assign performance

pull/2261/head
Hironsan 1 year ago
parent
commit
4002be2ea4
1 changed files with 4 additions and 2 deletions
  1. 6
      backend/examples/assignment/usecase.py

6
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") raise ValueError("Invalid member ids")
# Sort members by member_ids # Sort members by member_ids
members = sorted(members, key=lambda m: member_ids.index(m.id)) 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) 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() dataset_size = unassigned_examples.count()
strategy = create_assignment_strategy(strategy_name, dataset_size, weights) 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 = [ assignments = [
Assignment( Assignment(
project=project, 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 for assignment in assignments
] ]

Loading…
Cancel
Save