mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[performance] temporarily cache account status counts to reduce no. account counts (#2620)
* temporarily cache account status counts to reduce no. account counts
* whoops, forgot to initAccountCounts()
* use already fetched cache capacity value
* make cache a ptr type
* whoops, use count instead of just select
* fix to correctly use the transaction
* properly wrap that tx 😇
* correctly wrap both tx types
* outline retryOnBusy() to allow the fast path to be inlined
* return err on context cancelled
* remove unnecessary storage of context in stmt, fix Exec and Query interface implementations
* shutup linter
This commit is contained in:
23
internal/cache/db.go
vendored
23
internal/cache/db.go
vendored
@@ -36,6 +36,13 @@ type GTSCaches struct {
|
||||
// AccountNote provides access to the gtsmodel Note database cache.
|
||||
AccountNote structr.Cache[*gtsmodel.AccountNote]
|
||||
|
||||
// TEMPORARY CACHE TO ALLEVIATE SLOW COUNT QUERIES,
|
||||
// (in time will be removed when these IDs are cached).
|
||||
AccountCounts *simple.Cache[string, struct {
|
||||
Statuses int
|
||||
Pinned int
|
||||
}]
|
||||
|
||||
// Application provides access to the gtsmodel Application database cache.
|
||||
Application structr.Cache[*gtsmodel.Application]
|
||||
|
||||
@@ -192,6 +199,22 @@ func (c *Caches) initAccount() {
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Caches) initAccountCounts() {
|
||||
// Simply use size of accounts cache,
|
||||
// as this cache will be very small.
|
||||
cap := c.GTS.Account.Cap()
|
||||
if cap == 0 {
|
||||
panic("must be initialized before accounts")
|
||||
}
|
||||
|
||||
log.Infof(nil, "cache size = %d", cap)
|
||||
|
||||
c.GTS.AccountCounts = simple.New[string, struct {
|
||||
Statuses int
|
||||
Pinned int
|
||||
}](0, cap)
|
||||
}
|
||||
|
||||
func (c *Caches) initAccountNote() {
|
||||
// Calculate maximum cache size.
|
||||
cap := calculateResultCacheMax(
|
||||
|
Reference in New Issue
Block a user