Cache results of count(*) query for improved performance
- Dominant language
- Go
- Stars
- 5
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Description
The list endpoints (`User`, `Flavor`) call a Count() method on each model to get the total number of rows and return this value in the endpoint meta-data. In load testing, I found that the difference between using the results of this query vs. a static int value was about 50% req/sec (OUCH!)
I think this can be cached, since the count of users or flavors only changes when a flavor or user is added or deleted.
Refactor the create and delete handlers for Flavor, User to cache the record counts:
- This package? [https://github.com/patrickmn/go-cache](https://github.com/patrickmn/go-cache)
- Update the cache on successful create or delete operation. Caching operation should happen in the handler, not the DB/model layer.
- To update cache contents, run the model.Count() method to get the current count.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the User and Flavor list, create, and delete handlers, then trace their model Count() methods and the endpoint metadata. Check how successful mutations are reported before integrating the cache; done means list endpoints use cached counts and successful creates or deletes refresh those counts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100