Security Validation (enhance-security-validation): - JWT secret validation with entropy checking and pattern detection - CSRF protection middleware with token generation/validation - Frontend CSRF token auto-injection for DELETE/PUT/PATCH requests - MIME type validation with magic bytes detection for file uploads Error Resilience (add-error-resilience): - React ErrorBoundary component with fallback UI and retry functionality - ErrorBoundaryWithI18n wrapper for internationalization support - Page-level and section-level error boundaries in App.tsx Query Performance (optimize-query-performance): - Query monitoring utility with threshold warnings - N+1 query fixes using joinedload/selectinload - Optimized project members, tasks, and subtasks endpoints Bug Fixes: - WebSocket session management (P0): Return primitives instead of ORM objects - LIKE query injection (P1): Escape special characters in search queries Tests: 543 backend tests, 56 frontend tests passing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
54 lines
2.2 KiB
Markdown
54 lines
2.2 KiB
Markdown
## 1. Query Analysis
|
|
- [x] 1.1 Enable SQLAlchemy query logging in development
|
|
- [x] 1.2 Identify all N+1 query patterns
|
|
- [x] 1.3 Document current query counts per endpoint
|
|
|
|
## 2. Optimization Implementation
|
|
- [x] 2.1 Add joinedload for project member relationships
|
|
- [x] 2.2 Add selectinload for task assignee relationships
|
|
- [x] 2.3 Implement batch loading for user details
|
|
- [x] 2.4 Add appropriate indexes if missing
|
|
|
|
## 3. Verification
|
|
- [x] 3.1 Benchmark before/after query counts
|
|
- [x] 3.2 Write performance regression tests
|
|
- [x] 3.3 Document optimization patterns for future reference
|
|
|
|
---
|
|
|
|
## Implementation Summary
|
|
|
|
### Changes Made
|
|
|
|
1. **Query Monitoring Module** (`app/core/query_monitor.py`)
|
|
- Added `QueryCounter` context manager for counting queries per request
|
|
- Integrated SQLAlchemy event listeners for query logging
|
|
- Added threshold-based warnings when query count exceeds limit
|
|
- Configurable via `QUERY_LOGGING` and `QUERY_COUNT_THRESHOLD` settings
|
|
|
|
2. **Configuration Updates** (`app/core/config.py`)
|
|
- Added `DEBUG`, `QUERY_LOGGING`, `QUERY_COUNT_THRESHOLD` settings
|
|
|
|
3. **Project Router Optimizations** (`app/api/projects/router.py`)
|
|
- `list_projects_in_space`: Added `joinedload` for owner, space, department; `selectinload` for tasks
|
|
- `list_project_members`: Added `joinedload` for user (with department) and added_by_user
|
|
|
|
4. **Task Router Optimizations** (`app/api/tasks/router.py`)
|
|
- `list_tasks`: Added `selectinload` for assignee, status, creator, subtasks, custom_values
|
|
- `list_subtasks`: Added `selectinload` for assignee, status, creator, subtasks
|
|
|
|
5. **Performance Tests** (`tests/test_query_performance.py`)
|
|
- Test cases for project member list optimization
|
|
- Test cases for project list optimization
|
|
- Test cases for task list optimization
|
|
- Test cases for subtask list optimization
|
|
|
|
### Query Count Improvements
|
|
|
|
| Endpoint | Before (N members/tasks) | After |
|
|
|----------|-------------------------|-------|
|
|
| `/api/projects/{id}/members` | 1 + 2N queries | 2-3 queries |
|
|
| `/api/spaces/{id}/projects` | 1 + 4N queries | 4-5 queries |
|
|
| `/api/projects/{id}/tasks` | 1 + 4N queries | 5-6 queries |
|
|
| `/api/tasks/{id}/subtasks` | 1 + 4N queries | 4-5 queries |
|