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

Enable subproject filters for projects with subprojects #11674

Merged
merged 6 commits into from
Oct 15, 2024
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
8 changes: 4 additions & 4 deletions readthedocs/proxito/tests/test_hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ def test_number_of_queries_project_version_slug(self):
active=True,
)

with self.assertNumQueries(22):
with self.assertNumQueries(24):
r = self.client.get(
reverse("proxito_readthedocs_docs_addons"),
{
Expand Down Expand Up @@ -765,7 +765,7 @@ def test_number_of_queries_url(self):
active=True,
)

with self.assertNumQueries(24):
with self.assertNumQueries(26):
r = self.client.get(
reverse("proxito_readthedocs_docs_addons"),
{
Expand Down Expand Up @@ -801,7 +801,7 @@ def test_number_of_queries_url_subproject(self):
active=True,
)

with self.assertNumQueries(31):
with self.assertNumQueries(35):
r = self.client.get(
reverse("proxito_readthedocs_docs_addons"),
{
Expand All @@ -827,7 +827,7 @@ def test_number_of_queries_url_translations(self):
language=language,
)

with self.assertNumQueries(60):
with self.assertNumQueries(62):
r = self.client.get(
reverse("proxito_readthedocs_docs_addons"),
{
Expand Down
26 changes: 23 additions & 3 deletions readthedocs/proxito/views/hosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,7 @@ def _v1(self, project, version, build, filename, url, request):
# "Include subprojects",
# f"subprojects:{project.slug}/{version.slug}",
# ],
]
if version
else [],
],
"default_filter": f"project:{project.slug}/{version.slug}"
if version
else None,
Expand All @@ -514,6 +512,28 @@ def _v1(self, project, version, build, filename, url, request):
},
}

# Show the subprojects filter on the parent project and subproject
if version:
# TODO: Remove these queries and try to find a way to get this data
# from the resolver, which has already done these queries.
# TODO: Replace this fixed filters with the work proposed in
# https://github.com/readthedocs/addons/issues/22
if project.subprojects.exists():
data["addons"]["search"]["filters"].append(
[
"Include subprojects",
f"subprojects:{project.slug}/{version.slug}",
]
)
if project.superprojects.exists():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can save one query, since a project can't be both, a superproject and subproject.

Suggested change
if project.superprojects.exists():
elif project.superprojects.exists():

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

superproject = project.superprojects.first().parent
data["addons"]["search"]["filters"].append(
[
"Include subprojects",
f"subprojects:{superproject.slug}/{version.slug}",
]
)

# DocDiff depends on `url=` GET attribute.
# This attribute allows us to know the exact filename where the request was made.
# If we don't know the filename, we cannot return the data required by DocDiff to work.
Expand Down