Skip to content

Commit f67aa41

Browse files
committed
Proxito: always check 404/index.hmtml
With the introduction of `build.commands` we cannot use `version.documentation_type` anymore since those versions will be `generic` and we can't skip checking for this file location. Note this commit may add and extra call to S3 API for all the 404 pages where our regular Maze will be shown. However, it removes 2 databsae calls from all the 404 requests. We could only add this extra check on S3 for `version.documentation_type='generic'`, but that would make the code a little more complex and we won't be removing these 2 db queries. Reference: readthedocs/sphinx-notfound-page#215 (comment)
1 parent 77781b1 commit f67aa41

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

readthedocs/proxito/views/serve.py

+5-20
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from readthedocs.core.resolver import resolve_path
2020
from readthedocs.core.utils.extend import SettingsOverrideObject
2121
from readthedocs.projects import constants
22-
from readthedocs.projects.constants import SPHINX_HTMLDIR
2322
from readthedocs.projects.models import Feature
2423
from readthedocs.projects.templatetags.projects_tags import sort_version_aware
2524
from readthedocs.redirects.exceptions import InfiniteRedirectException
@@ -347,24 +346,14 @@ def get(self, request, proxito_path, template_name='404.html'):
347346
# If that doesn't work, attempt to serve the 404 of the current version (version_slug)
348347
# Secondly, try to serve the 404 page for the default version
349348
# (project.get_default_version())
350-
version = (
351-
Version.objects.filter(project=final_project, slug=version_slug)
352-
.only("documentation_type")
353-
.first()
354-
)
355349
versions = []
356-
if version:
357-
versions.append((version.slug, version.documentation_type))
350+
if Version.objects.filter(project=final_project, slug=version_slug).exists():
351+
versions.append(version_slug)
358352
default_version_slug = final_project.get_default_version()
359353
if default_version_slug != version_slug:
360-
default_version_doc_type = (
361-
Version.objects.filter(project=final_project, slug=default_version_slug)
362-
.values_list('documentation_type', flat=True)
363-
.first()
364-
)
365-
versions.append((default_version_slug, default_version_doc_type))
354+
versions.append(default_version_slug)
366355

367-
for version_slug_404, doc_type_404 in versions:
356+
for version_slug_404 in versions:
368357
if not self.allowed_user(request, final_project, version_slug_404):
369358
continue
370359

@@ -374,11 +363,7 @@ def get(self, request, proxito_path, template_name='404.html'):
374363
include_file=False,
375364
version_type=self.version_type,
376365
)
377-
tryfiles = ['404.html']
378-
# SPHINX_HTMLDIR is the only builder
379-
# that could output a 404/index.html file.
380-
if doc_type_404 == SPHINX_HTMLDIR:
381-
tryfiles.append('404/index.html')
366+
tryfiles = ["404.html", "404/index.html"]
382367
for tryfile in tryfiles:
383368
storage_filename_path = build_media_storage.join(storage_root_path, tryfile)
384369
if build_media_storage.exists(storage_filename_path):

0 commit comments

Comments
 (0)