mirror of
https://github.com/DRYTRIX/TimeTracker.git
synced 2026-05-19 12:50:11 -05:00
perf: Add eager loading for comment attachments in task view
- Add selectinload(Comment.attachments) to task comments query - Prevent N+1 queries when displaying comments with attachments - Improve performance for pages with multiple comments This optimization reduces database queries from N+1 to a single query for all attachments, significantly improving page load times.
This commit is contained in:
+3
-1
@@ -268,7 +268,9 @@ def view_task(task_id):
|
||||
joinedload(Comment.author), # Eagerly load author for all comments
|
||||
# Load replies with their authors - selectinload loads all direct replies in one query
|
||||
# This prevents N+1 queries when accessing comment.replies in the template
|
||||
selectinload(Comment.replies).joinedload(Comment.author)
|
||||
selectinload(Comment.replies).joinedload(Comment.author),
|
||||
# Eagerly load attachments to prevent N+1 queries
|
||||
selectinload(Comment.attachments)
|
||||
)
|
||||
.order_by(Comment.created_at.asc())
|
||||
.all()
|
||||
|
||||
Reference in New Issue
Block a user