Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Dev -> Prod #154

Merged
merged 2 commits into from
Jan 18, 2025
Merged
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
3 changes: 2 additions & 1 deletion accounts/api.py
Original file line number Diff line number Diff line change
@@ -348,7 +348,8 @@ def get(self, request: Request, *args, **kwargs):
{"message": f"Account with ID {account_id} not found."}, status=404
)

donations = Donation.objects.select_related('donor', 'pot', 'recipient', 'referrer', 'chef', 'token').prefetch_related('pot__admins').filter(donor=account) #TODO: this takes more time than just doing a prefetch_related for the fields.
# donations = account.donations.select_related('donor', 'pot', 'recipient', 'referrer', 'chef', 'token').prefetch_related('pot__admins').all()
donations = account.donations.select_related('donor', 'pot', 'pot__deployer', 'pot__owner', 'pot__chef', 'recipient', 'referrer', 'chef', 'token').prefetch_related('pot__admins').all()# (donor=account) #TODO: this takes more time than just doing a prefetch_related for the fields.
results = self.paginate_queryset(donations, request, view=self)
serializer = DonationSerializer(results, many=True)
return self.get_paginated_response(serializer.data)
26 changes: 9 additions & 17 deletions lists/api.py
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
from api.pagination import pagination_parameters
from api.pagination import CustomSizePageNumberPagination

from .models import List, ListRegistrationStatus
from .models import List, ListRegistration, ListRegistrationStatus
from .serializers import (
PAGINATED_LIST_EXAMPLE,
PAGINATED_LIST_REGISTRATION_EXAMPLE,
@@ -69,7 +69,7 @@ class ListsListAPI(APIView, CustomSizePageNumberPagination):
)
@method_decorator(cache_page(60 * 1))
def get(self, request: Request, *args, **kwargs):
lists = List.objects.all()
lists = List.objects.all().select_related("owner").prefetch_related("admins")
account_id = request.query_params.get("account")
if account_id:
try:
@@ -121,7 +121,7 @@ class ListDetailAPI(APIView):
def get(self, request: Request, *args, **kwargs):
list_id = kwargs.get("list_id")
try:
list_obj = List.objects.get(on_chain_id=list_id)
list_obj = List.objects.select_related("owner").prefetch_related("admins").get(on_chain_id=list_id)
except List.DoesNotExist:
return Response(
{"message": f"List with onchain ID {list_id} not found."}, status=404
@@ -176,14 +176,10 @@ class ListRegistrationsAPI(APIView, CustomSizePageNumberPagination):
@method_decorator(cache_page(60 * 1))
def get(self, request: Request, *args, **kwargs):
list_id = kwargs.get("list_id")
try:
list_obj = List.objects.prefetch_related('registrations').get(on_chain_id=list_id)
except List.DoesNotExist:
return Response(
{"message": f"List with on chain ID {list_id} not found."}, status=404
)
#list_obj = List.objects.prefetch_related('registrations').get(on_chain_id=list_id)
registrations = ListRegistration.objects.filter(list__on_chain_id=list_id).select_related("list__owner", "registrant", "registered_by").prefetch_related("list__admins")

registrations = list_obj.registrations.select_related().all()
# registrations = list_obj.registrations.select_related().all()
status_param = request.query_params.get("status")
category_param = request.query_params.get("category")
search_param = request.query_params.get("search")
@@ -239,14 +235,10 @@ class ListRandomRegistrationAPI(APIView):
)
def get(self, request: Request, *args, **kwargs):
list_id = kwargs.get("list_id")
try:
list_obj = List.objects.get(on_chain_id=list_id)
except List.DoesNotExist:
return Response(
{"message": f"List on chain ID {list_id} not found."}, status=404
)
# list_obj = List.objects.get(on_chain_id=list_id)
registrations = ListRegistration.objects.filter(list__on_chain_id=list_id).select_related("list__owner", "registrant", "registered_by").prefetch_related("list__admins")

registrations = list_obj.registrations.all()
# registrations = list_obj.registrations.all()
status_param = request.query_params.get("status")
if status_param:
if status_param not in ListRegistrationStatus.values:
4 changes: 2 additions & 2 deletions pots/api.py
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ class PotsListAPI(APIView, CustomSizePageNumberPagination):
)
@method_decorator(cache_page(60 * 5))
def get(self, request: Request, *args, **kwargs):
pots = Pot.objects.all()
pots = Pot.objects.select_related('account', 'pot_factory', 'deployer', 'owner', 'chef').prefetch_related('admins').all()
results = self.paginate_queryset(pots, request, view=self)
serializer = PotSerializer(results, many=True)
return self.get_paginated_response(serializer.data)
@@ -250,7 +250,7 @@ def get(self, request: Request, *args, **kwargs):
except Pot.DoesNotExist:
return Response({"message": f"Pot with ID {pot_id} not found."}, status=404)

donations = pot.donations.all()
donations = pot.donations.select_related("donor", "token", 'pot', 'pot__deployer', 'pot__owner', 'pot__chef', 'recipient', 'referrer', 'chef').prefetch_related('pot__admins').all()
results = self.paginate_queryset(donations, request, view=self)
serializer = DonationSerializer(results, many=True)
return self.get_paginated_response(serializer.data)
Loading