Skip to content

Commit

Permalink
fix(unit): add some missing prefetch() calls
Browse files Browse the repository at this point in the history
The prefetch_bulk() and prefetch_full() do prefetch unit data, but not
parent objects with assumption that these are typically called from
translation.unit_set where such prefetch is not needed. But when it
originates from Unit.objects, it needs to be added.
  • Loading branch information
nijel committed Oct 16, 2024
1 parent 4b633ca commit f29e7a1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Not yet released.
**Bug fixes**

* Update outdated plural definitions during the database migration.
* Reduced number of database queries when updating multiple strings.

**Compatibility**

Expand Down
7 changes: 6 additions & 1 deletion weblate/trans/autotranslate.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ def process_others(self, source: int | None) -> None:
.filter(source__in=translations.keys())
.values_list("id", flat=True)
)
units = Unit.objects.filter(pk__in=unit_ids).prefetch_bulk().select_for_update()
units = (
Unit.objects.filter(pk__in=unit_ids)
.prefetch()
.prefetch_bulk()
.select_for_update()
)
self.progress_steps = len(units)

for pos, unit in enumerate(units):
Expand Down
2 changes: 2 additions & 0 deletions weblate/trans/models/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1470,6 +1470,7 @@ def variants(self) -> Iterable[Unit]:
return []
return (
self.variant.unit_set.filter(translation=self.translation)
.prefetch()
.prefetch_full()
.order_by("context")
)
Expand Down Expand Up @@ -1642,6 +1643,7 @@ def checksum(self):
def same_source_units(self) -> UnitQuerySet:
return (
Unit.objects.same(self)
.prefetch()
.prefetch_full()
.filter(
translation__component__allow_translation_propagation=True,
Expand Down

0 comments on commit f29e7a1

Please sign in to comment.