-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Optimize resolve_path #6867
Optimize resolve_path #6867
Changes from 10 commits
546f390
558b7ae
ca62a45
fc9f296
2b5c295
93d838f
d763e88
a4b4282
489d6b1
58564a7
71c4ca1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,7 +103,6 @@ def resolve_path( | |
private=None, | ||
): | ||
"""Resolve a URL with a subset of fields defined.""" | ||
cname = cname or project.get_canonical_custom_domain() | ||
version_slug = version_slug or project.get_default_version() | ||
language = language or project.language | ||
|
||
|
@@ -112,28 +111,13 @@ def resolve_path( | |
|
||
filename = self._fix_filename(project, filename) | ||
|
||
current_project = project | ||
project_slug = project.slug | ||
subproject_slug = None | ||
# We currently support more than 2 levels of nesting subprojects and | ||
# translations, only loop twice to avoid sticking in the loop | ||
for _ in range(0, 2): | ||
main_language_project = current_project.main_language_project | ||
relation = current_project.get_parent_relationship() | ||
|
||
if main_language_project: | ||
current_project = main_language_project | ||
project_slug = main_language_project.slug | ||
language = project.language | ||
subproject_slug = None | ||
elif relation: | ||
current_project = relation.parent | ||
project_slug = relation.parent.slug | ||
subproject_slug = relation.alias | ||
cname = relation.parent.domains.filter(canonical=True).first() | ||
else: | ||
break | ||
|
||
main_project, subproject_slug = self._get_canonical_project_data(project) | ||
project_slug = main_project.slug | ||
cname = ( | ||
cname | ||
or self._use_subdomain() | ||
or main_project.get_canonical_custom_domain() | ||
) | ||
single_version = bool(project.single_version or single_version) | ||
|
||
return self.base_resolve_path( | ||
|
@@ -204,6 +188,68 @@ def resolve( | |
) | ||
return urlunparse((protocol, domain, path, '', query_params, '')) | ||
|
||
def _get_canonical_project_data(self, project): | ||
""" | ||
Returns a tuple with (project, subproject_slug) from the canonical project of `project`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 docstring! |
||
|
||
We currently support more than 2 levels of nesting subprojects and translations, | ||
but we only serve 2 levels to avoid sticking in the loop. | ||
This means, we can have the following cases: | ||
|
||
- The project isn't a translation or subproject | ||
|
||
We serve the documentation from the domain of the project itself | ||
(main.docs.com/). | ||
|
||
- The project is a translation of a project | ||
|
||
We serve the documentation from the domain of the main translation | ||
(main.docs.com/es/). | ||
|
||
- The project is a subproject of a project | ||
|
||
We serve the documentation from the domain of the super project | ||
(main.docs.com/projects/subproject/). | ||
|
||
- The project is a translation, and the main translation is a subproject of a project, like: | ||
|
||
- docs | ||
- api (subproject of ``docs``) | ||
- api-es (translation of ``api``, and current project to be served) | ||
|
||
We serve the documentation from the domain of the super project | ||
(docs.docs.com/projects/api/es/). | ||
|
||
- The project is a subproject, and the superproject is a translation of a project, like: | ||
|
||
- docs | ||
- docs-es (translation of ``docs``) | ||
- api-es (subproject of ``docs-es``, and current project to be served) | ||
|
||
We serve the documentation from the domain of the super project (the translation), | ||
this is docs-es.docs.com/projects/api-es/es/. | ||
We aren't going to support this case for now. | ||
|
||
In summary: If the project is a subproject, | ||
we don't care if the superproject is a translation, | ||
we always serve from the domain of the superproject. | ||
If the project is a translation, | ||
we need to check if the main translation is a subproject. | ||
""" | ||
main_project = project | ||
subproject_slug = None | ||
|
||
main_language_project = main_project.main_language_project | ||
if main_language_project: | ||
main_project = main_language_project | ||
|
||
relation = main_project.get_parent_relationship() | ||
if relation: | ||
main_project = relation.parent | ||
subproject_slug = relation.alias | ||
|
||
return (main_project, subproject_slug) | ||
|
||
def _get_canonical_project(self, project, projects=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can re-use the above method here if we don't't want to support more than 2 levels of relationships (thing that we already don't support actually...) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand this comment? re-use what method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is basically the same as |
||
""" | ||
Recursively get canonical project for subproject or translations. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we were making use of the real
cname
, but we only use it as a boolean value to see if we need to serve from/docs
instead of/
.