Skip to content

Commit 6ad9401

Browse files
committed
Addons: improve db query when adding HTTP header from El Proxito
We don't need the `Project` instance. We were using to check for a Feature flag, but now we are only adding the header when the project is using `build.commands`. If we ever require the `Project` instance again, we can do a `.select_related` from the `Version` object. That way, we still keep doing 1 query only. Closes #10458 Related #10456
1 parent ee52a2f commit 6ad9401

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

readthedocs/proxito/middleware.py

+8-15
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from django.urls import reverse
1717
from django.utils.deprecation import MiddlewareMixin
1818

19+
from readthedocs.builds.models import Version
1920
from readthedocs.core.unresolver import (
2021
InvalidCustomDomainError,
2122
InvalidExternalDomainError,
@@ -25,7 +26,7 @@
2526
unresolver,
2627
)
2728
from readthedocs.core.utils import get_cache_tag
28-
from readthedocs.projects.models import Feature, Project
29+
from readthedocs.projects.models import Feature
2930
from readthedocs.proxito.cache import add_cache_tags, cache_response, private_response
3031
from readthedocs.proxito.redirects import redirect_to_https
3132

@@ -293,20 +294,12 @@ def add_hosting_integrations_headers(self, request, response):
293294
project_slug = getattr(request, "path_project_slug", "")
294295
version_slug = getattr(request, "path_version_slug", "")
295296

296-
if project_slug:
297-
project = Project.objects.get(slug=project_slug)
298-
299-
# Check for the feature flag
300-
if project.has_feature(Feature.HOSTING_INTEGRATIONS):
301-
addons = True
302-
else:
303-
# Check if the version forces injecting the addons (e.g. using `build.commands`)
304-
version = (
305-
project.versions.filter(slug=version_slug).only("addons").first()
306-
)
307-
if version and version.addons:
308-
addons = True
309-
297+
if project_slug and version_slug:
298+
addons = Version.objects.filter(
299+
project__slug=project_slug,
300+
slug=version_slug,
301+
addons=True,
302+
).exists()
310303
if addons:
311304
response["X-RTD-Hosting-Integrations"] = "true"
312305

0 commit comments

Comments
 (0)