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 4 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
23 changes: 20 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,25 @@ def _v1(self, project, version, build, filename, url, request):
},
}

# Show the subprojects filter on the parent project and subproject
# TODO: Remove these queries and try to find a way to get this data
# from the resolver, which has already done these queries.
ericholscher marked this conversation as resolved.
Show resolved Hide resolved
if project.subprojects.exists():
ericholscher marked this conversation as resolved.
Show resolved Hide resolved
data["addons"]["search"]["filters"].append(
[
"Include subprojects",
f"subprojects:{project.slug}/{version.slug}",
]
)
if project.superprojects.exists():
superproject = project.superprojects.first().parent
data["addons"]["search"]["filters"].append(
[
"Include subprojects",
Copy link
Member

Choose a reason for hiding this comment

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

If you are reading a subproject, you want to get results from sibling projects -- since subprojects don't have other subprojects, but sibling ones.

Suggested change
"Include subprojects",
"Include sibling projects",

Copy link
Member Author

@ericholscher ericholscher Oct 15, 2024

Choose a reason for hiding this comment

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

I think subprojects is fine for the text here to not confuse users. If I go from a parent project to a subproject, it will be weird to have the text copy change in that case -- they are still "subprojects" in a certain sense, and I think keeping the UX the same makes it clearer.

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