Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prefetch metadata when downloading #14056

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Weblate 5.10.3

.. rubric:: Bug fixes

* Improved performance of API download endpoints.

.. rubric:: Compatibility

.. rubric:: Upgrading
Expand Down
4 changes: 2 additions & 2 deletions weblate/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
# Generate lookup
lookup = {}
category_path = ""
for field in reversed(self.lookup_fields):

Check failure on line 366 in weblate/api/views.py

View workflow job for this annotation

GitHub Actions / mypy

"MultipleFieldViewSet" has no attribute "lookup_fields"
if field not in {"component__slug", "slug"}:
lookup[field] = self.kwargs[field]
else:
Expand Down Expand Up @@ -567,7 +567,7 @@
return Response(serializer.data)


@extend_schema_view(

Check warning on line 570 in weblate/api/views.py

View workflow job for this annotation

GitHub Actions / API Lint

[GroupViewSet]: could not derive type of path parameter "language_code" because model "weblate.auth.models.Group" contained no such field. Consider annotating parameter with @extend_schema. Defaulting to "string".
retrieve=extend_schema(description="Return information about a group."),
partial_update=extend_schema(description="Change the group parameters."),
)
Expand All @@ -583,7 +583,7 @@
return Group.objects.order_by("id")
return self.request.user.groups.order_by(
"id"
) | self.request.user.administered_group_set.order_by("id")

Check failure on line 586 in weblate/api/views.py

View workflow job for this annotation

GitHub Actions / mypy

Item "AnonymousUser" of "User | AnonymousUser" has no attribute "administered_group_set"

Check failure on line 586 in weblate/api/views.py

View workflow job for this annotation

GitHub Actions / mypy

Unable to resolve return type of queryset/manager method "order_by"

def perm_check(self, request: Request, group: Group | None = None) -> None:
if (group is None and not self.request.user.has_perm("group.edit")) or (
Expand Down Expand Up @@ -760,7 +760,7 @@
raise ValidationError({"component_id": msg})

try:
component = Component.objects.filter_access(request.user).get(

Check failure on line 763 in weblate/api/views.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 to "filter_access" of "ComponentQuerySet" has incompatible type "User | AnonymousUser"; expected "User"
pk=int(request.data["component_id"])
)
except (Component.DoesNotExist, ValueError) as error:
Expand Down Expand Up @@ -867,9 +867,9 @@
@action(detail=True, methods=["get"])
def credits(self, request, **kwargs):
if request.user.is_anonymous:
self.permission_denied(request, "Must be authenticated to get credits")

Check failure on line 870 in weblate/api/views.py

View workflow job for this annotation

GitHub Actions / mypy

"CreditsMixin" has no attribute "permission_denied"

obj = self.get_object()

Check failure on line 872 in weblate/api/views.py

View workflow job for this annotation

GitHub Actions / mypy

"CreditsMixin" has no attribute "get_object"

try:
start_date = from_current_timezone(
Expand All @@ -893,10 +893,10 @@
language = request.query_params["lang"]

data = generate_credits(
None if request.user.has_perm("reports.view", obj) else request.user,

Check failure on line 896 in weblate/api/views.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 1 to "generate_credits" has incompatible type "Any | None"; expected "User"
start_date,
end_date,
language,

Check failure on line 899 in weblate/api/views.py

View workflow job for this annotation

GitHub Actions / mypy

Argument 4 to "generate_credits" has incompatible type "Any | None"; expected "str"
obj,
)
return Response(data=data)
Expand All @@ -913,7 +913,7 @@
):
"""Translation projects API."""

raw_urls: tuple[str, ...] = "project-file"

Check failure on line 916 in weblate/api/views.py

View workflow job for this annotation

GitHub Actions / mypy

Incompatible types in assignment (expression has type "str", variable has type "tuple[str, ...]")
raw_formats = ("zip", *(f"zip:{exporter}" for exporter in EXPORTERS))

queryset = Project.objects.none()
Expand Down Expand Up @@ -1138,7 +1138,7 @@

return download_multi(
cast("AuthenticatedHttpRequest", request),
translations,
translations.prefetch_meta(),
[instance],
requested_format,
name=instance.slug,
Expand Down Expand Up @@ -1247,7 +1247,7 @@
)


@extend_schema_view(

Check warning on line 1250 in weblate/api/views.py

View workflow job for this annotation

GitHub Actions / API Lint

[ComponentViewSet]: could not derive type of path parameter "project_slug" because model "weblate.trans.models.component.Component" contained no such field. Consider annotating parameter with @extend_schema. Defaulting to "string".
list=extend_schema(description="Return a list of translation components."),
retrieve=extend_schema(
description="Return information about translation component."
Expand Down Expand Up @@ -1528,7 +1528,7 @@
requested_format = request.query_params.get("format", "zip")
return download_multi(
cast("AuthenticatedHttpRequest", request),
instance.translation_set.all(),
instance.translation_set.prefetch_meta(),
[instance],
requested_format,
name=instance.full_slug.replace("/", "-"),
Expand Down Expand Up @@ -2141,7 +2141,7 @@
return Change.objects.preload_list(result)


@extend_schema_view(

Check warning on line 2144 in weblate/api/views.py

View workflow job for this annotation

GitHub Actions / API Lint

[ComponentListViewSet]: could not derive type of path parameter "component_slug" because model "weblate.trans.models.componentlist.ComponentList" contained no such field. Consider annotating parameter with @extend_schema. Defaulting to "string".
list=extend_schema(description="Return a list of component lists."),
retrieve=extend_schema(description="Return information about component list."),
partial_update=extend_schema(description="Change the component list parameters."),
Expand Down Expand Up @@ -2321,7 +2321,7 @@
return Response(serializer.data)


class Search(APIView):

Check failure on line 2324 in weblate/api/views.py

View workflow job for this annotation

GitHub Actions / API Lint

[Search]: unable to guess serializer. This is graceful fallback handling for APIViews. Consider using GenericAPIView as view base class, if view is under your control. Either way you may want to add a serializer_class (or method). Ignoring view for now.
"""Site-wide search endpoint."""

def get(self, request: Request, format=None): # noqa: A002
Expand Down Expand Up @@ -2377,7 +2377,7 @@
return Response(results)


@extend_schema_view(

Check failure on line 2380 in weblate/api/views.py

View workflow job for this annotation

GitHub Actions / API Lint

[TasksViewSet]: unable to guess serializer. This is graceful fallback handling for APIViews. Consider using GenericAPIView as view base class, if view is under your control. Either way you may want to add a serializer_class (or method). Ignoring view for now.
list=extend_schema(description="Listing of the tasks is currently not available.")
)
class TasksViewSet(ViewSet):
Expand Down
2 changes: 1 addition & 1 deletion weblate/trans/views/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
if os.path.exists(fullname):
filenames.add(fullname)

return zip_download(data_dir("vcs"), sorted(filenames), name, extra=extra)

Check failure on line 97 in weblate/trans/views/files.py

View workflow job for this annotation

GitHub Actions / mypy

Argument "extra" to "zip_download" has incompatible type "dict[str, str]"; expected "dict[str, bytes] | None"


def download_component_list(request: AuthenticatedHttpRequest, name):
Expand Down Expand Up @@ -181,7 +181,7 @@
if isinstance(obj, Component):
return download_multi(
request,
obj.translation_set.all(),
obj.translation_set.prefetch_meta(),
[obj],
request.GET.get("format"),
name=obj.full_slug.replace("/", "-"),
Expand Down
Loading