Skip to content

Commit

Permalink
Comments: Utilize prefetch
Browse files Browse the repository at this point in the history
This reduces amount of queries on heavily commented strings.
  • Loading branch information
nijel committed Sep 21, 2020
1 parent f7b2b8e commit f2d3235
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions weblate/trans/models/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,13 +845,19 @@ def active_checks(self):
def all_comments(self):
"""Return list of target comments."""
query = Q(unit=self)
if self.source_unit:
# Add source string comments for translation unit
query |= Q(unit=self.source_unit)
else:
if self.translation.is_source:
# Add all comments on translation on source string comment
query |= Q(unit__source_unit=self)
return Comment.objects.filter(query).prefetch_related("unit").order()
else:
# Add source string comments for translation unit
query |= Q(unit=self.source_unit)
return (
Comment.objects.filter(query)
.prefetch_related(
"unit", "unit__translation", "unit__translation__component", "user"
)
.order()
)

@cached_property
def unresolved_comments(self):
Expand Down

0 comments on commit f2d3235

Please sign in to comment.