|
3 | 3 | from rest_framework.serializers import ModelSerializer |
4 | 4 |
|
5 | 5 | from django.conf import settings |
| 6 | +from django.core.cache import cache |
6 | 7 |
|
7 | 8 | from accounts.serializers import SIMPLE_ACCOUNT_EXAMPLE, AccountSerializer, NearSocialProfileDataSerializer |
8 | 9 | from base.serializers import TwoDecimalPlacesField |
@@ -355,19 +356,31 @@ class MpdaoSnapshotSerializer(serializers.Serializer): |
355 | 356 |
|
356 | 357 | def get_is_human(self, obj) -> bool: |
357 | 358 | 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" |
359 | 365 | response = requests.get(url) |
360 | 366 | if response.status_code == 200: |
361 | 367 | is_human = response.json() |
| 368 | + cache.set(cache_key, is_human, 8640000) |
362 | 369 | return is_human |
363 | 370 | return False |
364 | 371 |
|
365 | 372 | def get_staking_token_balance(self, obj): |
366 | 373 | 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" |
368 | 380 | response = requests.get(url) |
369 | 381 | if response.status_code == 200: |
370 | 382 | balance = response.json() |
| 383 | + cache.set(cache_key, balance, 8640000) |
371 | 384 | return balance |
372 | 385 | return "0" |
373 | 386 |
|
|
0 commit comments