Skip to content

Commit b723515

Browse files
authoredJan 20, 2025
Merge pull request #162 from PotLock/dev
Dev -> Prod
2 parents 9f9c4d8 + 2406f52 commit b723515

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed
 

‎pots/api.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def get_bulk_account_data(self, voter_ids):
382382
"""Get account data for multiple voters in one query"""
383383
accounts = {
384384
account.id: AccountSerializer(account).data
385-
for account in Account.objects.select_related().filter(id__in=voter_ids)
385+
for account in Account.objects.filter(id__in=voter_ids)
386386
}
387387
return accounts
388388

@@ -418,7 +418,7 @@ class MpdaoVotersListAPI(MpdaoVoterMixin, APIView):
418418
500: OpenApiResponse(description="Error fetching voters"),
419419
},
420420
)
421-
@method_decorator(cache_page(14400))
421+
@method_decorator(cache_page(86400))
422422
def get(self, request: Request, *args, **kwargs):
423423
try:
424424
return self.get_all_voters(request.query_params)
@@ -515,13 +515,13 @@ class MpdaoVoterDetailAPI(MpdaoVoterMixin, APIView):
515515
500: OpenApiResponse(description="Error fetching voter data"),
516516
},
517517
)
518-
@method_decorator(cache_page(14400))
518+
@method_decorator(cache_page(86400))
519519
def get(self, request: Request, voter_id: str, *args, **kwargs):
520520
try:
521521
voter_data = self.get_voter_data(voter_id)
522522

523-
accounts = self.get_bulk_account_data([voter_id])
524-
account_data = accounts.get(voter_id)
523+
# accounts = self.get_bulk_account_data([voter_id])
524+
account_data = accounts = AccountSerializer(voter_id).data
525525

526526
response_data = {
527527
"voter_id": voter_id,

‎pots/serializers.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from rest_framework.serializers import ModelSerializer
44

55
from django.conf import settings
6+
from django.core.cache import cache
67

78
from accounts.serializers import SIMPLE_ACCOUNT_EXAMPLE, AccountSerializer, NearSocialProfileDataSerializer
89
from base.serializers import TwoDecimalPlacesField
@@ -355,19 +356,31 @@ class MpdaoSnapshotSerializer(serializers.Serializer):
355356

356357
def get_is_human(self, obj) -> bool:
357358
voter_id = obj.get('voter_id')
358-
url = f"https://rpc.web4.near.page/account/v1.nadabot.near/view/is_human?account_id={voter_id}"
359+
cache_key = f'{voter_id}_is_human'
360+
cached_res = cache.get(cache_key)
361+
362+
if cached_res is not None:
363+
return cached_res
364+
url = f"https://rpc.web4.near.page/account/v1.nadabot.near/view/is_human?account_id={voter_id}&near_block_height=137346724"
359365
response = requests.get(url)
360366
if response.status_code == 200:
361367
is_human = response.json()
368+
cache.set(cache_key, is_human, 8640000)
362369
return is_human
363370
return False
364371

365372
def get_staking_token_balance(self, obj):
366373
voter_id = obj.get('voter_id')
367-
url = f"https://rpc.web4.near.page/account/meta-pool.near/view/ft_balance_of?account_id={voter_id}"
374+
cache_key = f'{voter_id}_token_balance'
375+
cached_res = cache.get(cache_key)
376+
377+
if cached_res is not None:
378+
return cached_res
379+
url = f"https://rpc.web4.near.page/account/meta-pool.near/view/ft_balance_of?account_id={voter_id}&near_block_height=137346724"
368380
response = requests.get(url)
369381
if response.status_code == 200:
370382
balance = response.json()
383+
cache.set(cache_key, balance, 8640000)
371384
return balance
372385
return "0"
373386

0 commit comments

Comments
 (0)