Feature improvement #15383
Updated by Peter Mačuga 7 months ago
Slide - update the preprocesseing flow and structure of the KillEvent (GroupedKillEvent) Task Service - create a new handle event method for GroupedKillEvent as it has a different flow than the old handle event method (we might still need it so keep it as it is) - ideally only make 1 database commit per GroupedKillEvent, making it more efficient and less buggy. - optimize the update calls, calculate the points per GroupedKillEvent first, then commit them together in the least amount of updates as possible. ``` python # Get associated users and their assigned tasks users = get_associated_users() assigned_tasks tasks = get_assigned_tasks_from_index() # Map Assigned Tasks (AT) to users' tasks mapped_tasks = map_tasks_to_users(users, tasks) # Initialize an empty update dictionary updates = {} # Iterate over each assigned task for task in assigned_tasks: mapped_tasks: # Validate task data against the JSON schema if validate_json_schema(assigned_tasks.task): validate_json_schema(task): # Increment the task count in the update dictionary for the user user_id = assigned_tasks.user_id task.assigned_user_id task_id = task.id # Initialize user entry in the update dictionary if needed if user_id not in updates: updates[user_id] = {} # Increment task count for this task in user's update dictionary updates[user_id][assigned_task.id] updates[user_id][task_id] = updates[user_id].get(assigned_task.id, updates[user_id].get(task_id, 0) + 1 # Apply updates for each user for user_id in updates: # Get the user's assigned tasks user_tasks = get_tasks_for_user(user_id) # Iterate through each task in the user's list for assigned_tasks task in user_tasks: assigned_task.progress task_id = task.id # Update task progress if it's in the update dictionary if task_id in updates[user_id]: task.progress += updates[user_id][task_id] # Commit the updates for the user commit_user_updates(user_id) ```