Cache resource heavy endpoints #21
Labels
No labels
bug
documentation
duplicate
enhancement
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
gertjan/bodega#21
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The current situation is that the homepage makes five calls to populate all the widgets. Four of those calls are to the
/analytics/top-performersendpoint. These calls are resource‑intensive, especially when the user selects an exchange with many stocks (e.g. NASDAQ). Also, every time the user visits or refreshes the page, those calls are made again. This results in quite a big queue which halts all the endpoints. In my opinion, we can cache these resource‑heavy endpoints because they do not change very often, particularly the monthly and yearly performer data.changed the description
marked this issue as related to #19
Fixed in
6bc219bwith two changes tosrc/api/cache.py: (1) in-flight request deduplication — concurrent requests for the same cache key now coalesce onto a single asyncio Future instead of all hitting the DB simultaneously, preventing the thundering herd from the homepage's four paralleltop-performerscalls; (2) per-endpoint TTL support, used to givetop-performersa 1-hour TTL instead of the global 5 minutes, since the data barely changes within a trading day.