Skip to content

Commit

Permalink
feat: prefetch all needed fields for notification
Browse files Browse the repository at this point in the history
This avoids race condition on disappearing attributes and reduces
overhead.

Fixes WEBLATE-16AA
  • Loading branch information
nijel committed Dec 11, 2024
1 parent 266dbe5 commit 99aeec3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions weblate/trans/models/change.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,22 @@ def base_stats(
return base.count_stats(days, step, dtstart)

def prefetch_for_get(self):
return self.select_related(*PREFETCH_FIELDS)
return self.select_related(
"alert",
"screenshot",
"announcement",
"suggestion",
"comment",
*PREFETCH_FIELDS,
)

def prefetch(self):
"""
Fetch related fields at once to avoid loading them individually.
Call prefetch or prefetch_list later on paginated results to complete.
"""
return self.prefetch_related("alert", *PREFETCH_FIELDS)
return self.prefetch_related(*PREFETCH_FIELDS)

def preload_list(self, results, skip: str | None = None):
"""Companion for prefetch to fill in nested references."""
Expand Down

0 comments on commit 99aeec3

Please sign in to comment.