Skip to content

Commit

Permalink
component: use prefetch instead of all
Browse files Browse the repository at this point in the history
The prefetch fetches categories needed to build full slug and defers
loading of huge fields like commit messages what both have positive
performance impacts.
  • Loading branch information
nijel committed Oct 11, 2023
1 parent d0bfe7e commit 2336ab2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions weblate/memory/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ def import_memory(project_id: int, component_id: int | None = None):

project = Project.objects.get(pk=project_id)

components = project.component_set.all()
components = project.component_set.prefetch()
if component_id:
components = components.filter(id=component_id)

for component in components.iterator():
for component in components:
component.log_info("updating translation memory")
with transaction.atomic():
units = Unit.objects.filter(
Expand Down
6 changes: 4 additions & 2 deletions weblate/memory/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ def form_valid(self, form):
if origin:
slugs = [origin]
else:
slugs = [component.full_slug for component in project.component_set.all()]
slugs = [
component.full_slug for component in project.component_set.prefetch()
]
Memory.objects.filter(origin__in=slugs, shared=True).delete()
# Rebuild memory in background
import_memory.delay(project_id=project.id, component_id=component_id)
Expand Down Expand Up @@ -172,7 +174,7 @@ def get_url(slug: str) -> str:
if "project" in self.objects:
slugs = {
component.full_slug
for component in self.objects["project"].component_set.all()
for component in self.objects["project"].component_set.prefetch()
}
existing = {entry["origin"] for entry in result}
for entry in result:
Expand Down
2 changes: 1 addition & 1 deletion weblate/templates/browse.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{% block content %}

{% if object.component.slug == "-" %}
{% for component in project.component_set.all %}
{% for component in project.component_set.prefetch %}
{% include "snippets/component/state.html" with object=component %}
{% endfor %}
{% else %}
Expand Down
2 changes: 1 addition & 1 deletion weblate/templates/zen.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{% block content %}

{% if object.component.slug == "-" %}
{% for component in project.component_set.all %}
{% for component in project.component_set.prefetch %}
{% include "snippets/component/state.html" with object=component %}
{% endfor %}
{% else %}
Expand Down

0 comments on commit 2336ab2

Please sign in to comment.