Skip to content

Cache Horizon account lookups briefly#375

Open
silentgeckoaudit3801 wants to merge 2 commits into
Quantarq:mainfrom
silentgeckoaudit3801:perf/cache-horizon-account-data-240
Open

Cache Horizon account lookups briefly#375
silentgeckoaudit3801 wants to merge 2 commits into
Quantarq:mainfrom
silentgeckoaudit3801:perf/cache-horizon-account-data-240

Conversation

@silentgeckoaudit3801

Copy link
Copy Markdown

Summary

  • wrap _get_account_data in the existing get_cached_or_fetch helper with a 5 second TTL
  • key the cache by Horizon base URL and account address
  • keep the Horizon fetch/error handling behavior inside a nested fetch function
  • add a static regression test for the cache wiring

Validation

  • Static API validation confirmed _get_account_data has a single implementation, uses ttl=5, includes the Horizon/account cache key, and preserves the following get_token_balances method signature
  • Compare is 0 commits behind upstream main

Closes #240

def test_get_account_data_uses_horizon_account_cache():
source = Path("quantara/web_app/contract_tools/blockchain_call.py").read_text(encoding="utf-8")

assert "cache_key = f\"horizon:account:" in source
source = Path("quantara/web_app/contract_tools/blockchain_call.py").read_text(encoding="utf-8")

assert "cache_key = f\"horizon:account:" in source
assert "get_cached_or_fetch(cache_key, ttl=5, fetch_fn=fetch_account)" in source

assert "cache_key = f\"horizon:account:" in source
assert "get_cached_or_fetch(cache_key, ttl=5, fetch_fn=fetch_account)" in source
assert "async def fetch_account()" in source No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache Horizon /accounts/{id} 5s

2 participants