Optimize shot table loading performance

- Pass episode_id filter to backend API instead of client-side filtering,
  reducing payload size when an episode is selected
- Skip getShot refetch in ShotDetailPanel when initialShot prop is provided
- Fix redundant DB query in list_shots: read project.custom_task_statuses
  directly from the already-fetched project object
- Add missing indexes on Task.shot_id, Task.assigned_user_id,
  Task.deleted_at and Episode.project_id; add add_perf_indexes.py
  migration script to apply them to existing databases
- Center login page layout
- Update CLAUDE.md and AGENTS.md with correct venv path

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-22 00:30:18 +08:00
parent 0dd37d1706
commit 0acf9ddff2
13 changed files with 151 additions and 81 deletions
+61 -1
View File
@@ -266,9 +266,17 @@ async def list_shots(
)
for project in projects:
custom_types = project.custom_shot_task_types or []
raw = project.custom_task_statuses
if isinstance(raw, str):
try:
import json
raw = json.loads(raw)
except (json.JSONDecodeError, TypeError):
raw = []
custom_statuses = raw if isinstance(raw, list) else []
project_data[project.id] = {
'task_types': STANDARD_SHOT_TASK_TYPES + custom_types,
'custom_statuses': get_project_custom_statuses(project.id, db)
'custom_statuses': custom_statuses
}
# OPTIMIZATION: Group results by shot and aggregate task data efficiently
@@ -606,6 +614,58 @@ async def get_shot(
shot_data = ShotResponse.model_validate(shot)
shot_data.task_count = task_count
# Add project_name from episode.project (already eager loaded)
if shot.episode and shot.episode.project:
shot_data.project_name = shot.episode.project.name
# Add task status information (similar to list endpoint)
project = shot.episode.project if shot.episode else None
# Get all task types: standard + custom
from routers.shots import STANDARD_SHOT_TASK_TYPES
project_task_types = list(STANDARD_SHOT_TASK_TYPES) # Start with standard types
if project and project.custom_shot_task_types:
custom_types = project.custom_shot_task_types or []
if isinstance(custom_types, list):
for ct in custom_types:
if isinstance(ct, dict) and 'type' in ct:
project_task_types.append(ct['type'])
elif isinstance(ct, str):
project_task_types.append(ct)
# Initialize task_status and task_ids dictionaries
task_status_dict = {}
task_ids_dict = {}
task_details_list = []
# Initialize with default not_started for all project task types
for task_type_init in project_task_types:
task_status_dict[task_type_init] = "not_started"
# Build task information from active tasks
for task in active_tasks:
task_type = task.task_type.value if hasattr(task.task_type, 'value') else task.task_type
task_status = task.status.value if hasattr(task.status, 'value') else task.status
task_id = task.id
assigned_user_id = task.assigned_user_id
# Update task status
task_status_dict[task_type] = task_status
task_ids_dict[task_type] = task_id
# Add to task details
task_details_list.append(TaskStatusInfo(
task_type=task_type,
status=task_status,
task_id=task_id,
assigned_user_id=assigned_user_id
))
shot_data.task_status = task_status_dict
shot_data.task_ids = task_ids_dict
shot_data.task_details = task_details_list
return shot_data