Skip to content

Commit

Permalink
views: optimize fetching ghost translations
Browse files Browse the repository at this point in the history
Perform the filtering in the database and use comprehension to update the list.
  • Loading branch information
nijel committed Oct 11, 2023
1 parent 9261eaa commit c127309
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions weblate/trans/views/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,14 @@ def show_project_language(request, obj):
# Add ghost translations
if user.is_authenticated:
existing = {translation.component.slug for translation in translations}
for component in project_object.child_components:
if component.slug in existing:
continue
if component.can_add_new_language(user, fast=True):
translations.append(GhostTranslation(component, language_object))
missing = project_object.get_child_components_filter(
lambda qs: qs.exclude(slug__in=existing)
)
translations.extend(
GhostTranslation(component, language_object)
for component in missing
if component.can_add_new_language(user, fast=True)
)

return render(
request,
Expand Down Expand Up @@ -296,11 +299,12 @@ def show_category_language(request, obj):
# Add ghost translations
if user.is_authenticated:
existing = {translation.component.slug for translation in translations}
for component in category_object.component_set.all():
if component.slug in existing:
continue
if component.can_add_new_language(user, fast=True):
translations.append(GhostTranslation(component, language_object))
missing = category_object.component_set.exclude(slug__in=existing)
translations.extend(
GhostTranslation(component, language_object)
for component in missing
if component.can_add_new_language(user, fast=True)
)

return render(
request,
Expand Down

0 comments on commit c127309

Please sign in to comment.