Skip to content

Commit e85ee7d

Browse files
authored
Proxito: save one queryset (#9980)
1 parent 5cea411 commit e85ee7d

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

readthedocs/proxito/views/decorators.py

+13-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import structlog
21
from functools import wraps
32

3+
import structlog
4+
from django.db.models import Q
45
from django.http import Http404
56

67
from readthedocs.projects.models import Project, ProjectRelationship
@@ -25,26 +26,20 @@ def inner_view( # noqa
2526
# Try to fetch by subproject alias first, otherwise we might end up
2627
# redirected to an unrelated project.
2728
# Depends on a project passed into kwargs
28-
rel = ProjectRelationship.objects.filter(
29-
parent=kwargs['project'],
30-
alias=subproject_slug,
31-
).first()
29+
rel = (
30+
ProjectRelationship.objects.filter(parent=kwargs["project"])
31+
.filter(Q(alias=subproject_slug) | Q(child__slug=subproject_slug))
32+
.first()
33+
)
3234
if rel:
3335
subproject = rel.child
3436
else:
35-
rel = ProjectRelationship.objects.filter(
36-
parent=kwargs['project'],
37-
child__slug=subproject_slug,
38-
).first()
39-
if rel:
40-
subproject = rel.child
41-
else:
42-
log.warning(
43-
'The slug is not subproject of project.',
44-
subproject_slug=subproject_slug,
45-
project_slug=kwargs['project'].slug,
46-
)
47-
raise Http404('Invalid subproject slug')
37+
log.warning(
38+
"The slug is not subproject of project.",
39+
subproject_slug=subproject_slug,
40+
project_slug=kwargs["project"].slug,
41+
)
42+
raise Http404("Invalid subproject slug")
4843
return view_func(request, subproject=subproject, *args, **kwargs)
4944

5045
return inner_view

0 commit comments

Comments
 (0)