summaryrefslogtreecommitdiff
path: root/internal/cache/db.go
diff options
context:
space:
mode:
authorLibravatar Vyr Cossont <VyrCossont@users.noreply.github.com>2024-06-06 09:38:02 -0700
committerLibravatar GitHub <noreply@github.com>2024-06-06 16:38:02 +0000
commit5e2d4fdb19eb4fcd4c0bbfb3e2f29067a58c88c8 (patch)
tree607006af6b4bb63bb625b39f3ca0fe869eb6ba95 /internal/cache/db.go
parent[bugfix] update media if more than just url changes (#2970) (diff)
downloadgotosocial-5e2d4fdb19eb4fcd4c0bbfb3e2f29067a58c88c8.tar.xz
[feature] User muting (#2960)
* User muting * Address review feedback * Rename uniqueness constraint on user_mutes to match convention * Remove unused account_id from where clause * Add UserMute to NewTestDB * Update test/envparsing.sh with new and fixed cache stuff * Address tobi's review comments * Make compiledUserMuteListEntry.expired consistent with UserMute.Expired * Make sure mute_expires_at is serialized as an explicit null for indefinite mutes --------- Co-authored-by: tobi <tobi.smethurst@protonmail.com>
Diffstat (limited to 'internal/cache/db.go')
-rw-r--r--internal/cache/db.go53
1 files changed, 52 insertions, 1 deletions
diff --git a/internal/cache/db.go b/internal/cache/db.go
index a5325f6ef..e00c02701 100644
--- a/internal/cache/db.go
+++ b/internal/cache/db.go
@@ -47,7 +47,7 @@ type GTSCaches struct {
// Block provides access to the gtsmodel Block (account) database cache.
Block StructCache[*gtsmodel.Block]
- // FollowIDs provides access to the block IDs database cache.
+ // BlockIDs provides access to the block IDs database cache.
BlockIDs SliceCache[string]
// BoostOfIDs provides access to the boost of IDs list database cache.
@@ -166,6 +166,12 @@ type GTSCaches struct {
// User provides access to the gtsmodel User database cache.
User StructCache[*gtsmodel.User]
+ // UserMute provides access to the gtsmodel UserMute database cache.
+ UserMute StructCache[*gtsmodel.UserMute]
+
+ // UserMuteIDs provides access to the user mute IDs database cache.
+ UserMuteIDs SliceCache[string]
+
// Webfinger provides access to the webfinger URL cache.
// TODO: move out of GTS caches since unrelated to DB.
Webfinger *ttl.Cache[string, string] // TTL=24hr, sweep=5min
@@ -1347,6 +1353,51 @@ func (c *Caches) initUser() {
})
}
+func (c *Caches) initUserMute() {
+ cap := calculateResultCacheMax(
+ sizeofUserMute(), // model in-mem size.
+ config.GetCacheUserMuteMemRatio(),
+ )
+
+ log.Infof(nil, "cache size = %d", cap)
+
+ copyF := func(u1 *gtsmodel.UserMute) *gtsmodel.UserMute {
+ u2 := new(gtsmodel.UserMute)
+ *u2 = *u1
+
+ // Don't include ptr fields that
+ // will be populated separately.
+ // See internal/db/bundb/relationship_mute.go.
+ u2.Account = nil
+ u2.TargetAccount = nil
+
+ return u2
+ }
+
+ c.GTS.UserMute.Init(structr.CacheConfig[*gtsmodel.UserMute]{
+ Indices: []structr.IndexConfig{
+ {Fields: "ID"},
+ {Fields: "AccountID,TargetAccountID"},
+ {Fields: "AccountID", Multiple: true},
+ {Fields: "TargetAccountID", Multiple: true},
+ },
+ MaxSize: cap,
+ IgnoreErr: ignoreErrors,
+ Copy: copyF,
+ Invalidate: c.OnInvalidateUserMute,
+ })
+}
+
+func (c *Caches) initUserMuteIDs() {
+ cap := calculateSliceCacheMax(
+ config.GetCacheUserMuteIDsMemRatio(),
+ )
+
+ log.Infof(nil, "cache size = %d", cap)
+
+ c.GTS.UserMuteIDs.Init(0, cap)
+}
+
func (c *Caches) initWebfinger() {
// Calculate maximum cache size.
cap := calculateCacheMax(