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

API: separate querysets from API V2 and V3 #11586

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions readthedocs/api/v2/views/model_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def get_queryset(self):
api_key = getattr(self.request, "build_api_key", None)
if api_key:
return self.get_queryset_for_api_key(api_key)
return self.model.objects.api(self.request.user)
return self.model.objects.api_v2(self.request.user)


class ProjectViewSet(DisableListEndpoint, UpdateModelMixin, UserSelectViewSet):
Expand Down Expand Up @@ -415,7 +415,7 @@ class RemoteOrganizationViewSet(viewsets.ReadOnlyModelViewSet):

def get_queryset(self):
return (
self.model.objects.api(self.request.user)
self.model.objects.api_v2(self.request.user)
.filter(
remote_organization_relations__account__provider__in=[
service.adapter.provider_id for service in registry
Expand All @@ -437,7 +437,7 @@ def get_queryset(self):
return self.model.objects.none()

# TODO: Optimize this query after deployment
query = self.model.objects.api(self.request.user).annotate(
query = self.model.objects.api_v2(self.request.user).annotate(
admin=Case(
When(
remote_repository_relations__user=self.request.user,
Expand Down
1 change: 1 addition & 0 deletions readthedocs/api/v3/tests/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def setUp(self):
has_pdf=True,
has_epub=True,
has_htmlzip=True,
privacy_level=PUBLIC,
)

self.organization = fixture.get(
Expand Down
9 changes: 9 additions & 0 deletions readthedocs/builds/querysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ def public(
def api(self, user=None):
return self.public(user, only_active=False)

def api_v2(self, *args, **kwargs):
return self.api(*args, **kwargs)
stsewd marked this conversation as resolved.
Show resolved Hide resolved

def for_reindex(self):
"""
Get all versions that can be reindexed.
Expand Down Expand Up @@ -205,6 +208,9 @@ def public(self, user=None, project=None):
def api(self, user=None):
return self.public(user)

def api_v2(self, *args, **kwargs):
return self.api(*args, **kwargs)

def concurrent(self, project):
"""
Check if the max build concurrency for this project was reached.
Expand Down Expand Up @@ -305,3 +311,6 @@ def public(self, user=None):

def api(self, user=None):
return self.public(user)

def api_v2(self, *args, **kwargs):
return self.api(*args, **kwargs)
3 changes: 3 additions & 0 deletions readthedocs/oauth/querysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def api(self, user=None):
return self.none()
return self.filter(users=user)

def api_v2(self, *args, **kwargs):
return self.api(*args, **kwargs)


class RemoteRepositoryQuerySet(RelatedUserQuerySet):
def for_project_linking(self, user):
Expand Down
6 changes: 6 additions & 0 deletions readthedocs/projects/querysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ def dashboard(self, user):
def api(self, user=None):
return self.public(user)

def api_v2(self, *args, **kwargs):
return self.api(*args, **kwargs)

def single_owner(self, user):
"""
Returns projects where `user` is the only owner.
Expand Down Expand Up @@ -210,6 +213,9 @@ def public(self, user=None, project=None):
def api(self, user=None):
return self.public(user)

def api_v2(self, *args, **kwargs):
return self.api(*args, **kwargs)


class ParentRelatedProjectQuerySet(RelatedProjectQuerySet):
project_field = "parent"
Expand Down
3 changes: 3 additions & 0 deletions readthedocs/redirects/querysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def api(self, user=None):
queryset = self._add_from_user_projects(queryset, user)
return queryset

def api_v2(self, *args, **kwargs):
return self.api(*args, **kwargs)

def get_matching_redirect_with_path(
self, filename, path=None, language=None, version_slug=None, forced_only=False
):
Expand Down