summaryrefslogtreecommitdiff
path: root/internal/cache/db.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/cache/db.go')
-rw-r--r--internal/cache/db.go51
1 files changed, 27 insertions, 24 deletions
diff --git a/internal/cache/db.go b/internal/cache/db.go
index cb0ed6712..d993d6143 100644
--- a/internal/cache/db.go
+++ b/internal/cache/db.go
@@ -20,7 +20,6 @@ package cache
import (
"time"
- "codeberg.org/gruf/go-cache/v3/simple"
"codeberg.org/gruf/go-cache/v3/ttl"
"codeberg.org/gruf/go-structr"
"github.com/superseriousbusiness/gotosocial/internal/cache/domain"
@@ -36,16 +35,12 @@ type GTSCaches struct {
// AccountNote provides access to the gtsmodel Note database cache.
AccountNote StructCache[*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
- }]
-
// AccountSettings provides access to the gtsmodel AccountSettings database cache.
AccountSettings StructCache[*gtsmodel.AccountSettings]
+ // AccountStats provides access to the gtsmodel AccountStats database cache.
+ AccountStats StructCache[*gtsmodel.AccountStats]
+
// Application provides access to the gtsmodel Application database cache.
Application StructCache[*gtsmodel.Application]
@@ -200,6 +195,7 @@ func (c *Caches) initAccount() {
a2.AlsoKnownAs = nil
a2.Move = nil
a2.Settings = nil
+ a2.Stats = nil
return a2
}
@@ -223,22 +219,6 @@ 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(
@@ -295,6 +275,29 @@ func (c *Caches) initAccountSettings() {
})
}
+func (c *Caches) initAccountStats() {
+ // Calculate maximum cache size.
+ cap := calculateResultCacheMax(
+ sizeofAccountStats(), // model in-mem size.
+ config.GetCacheAccountStatsMemRatio(),
+ )
+
+ log.Infof(nil, "cache size = %d", cap)
+
+ c.GTS.AccountStats.Init(structr.CacheConfig[*gtsmodel.AccountStats]{
+ Indices: []structr.IndexConfig{
+ {Fields: "AccountID"},
+ },
+ MaxSize: cap,
+ IgnoreErr: ignoreErrors,
+ Copy: func(s1 *gtsmodel.AccountStats) *gtsmodel.AccountStats {
+ s2 := new(gtsmodel.AccountStats)
+ *s2 = *s1
+ return s2
+ },
+ })
+}
+
func (c *Caches) initApplication() {
// Calculate maximum cache size.
cap := calculateResultCacheMax(