mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[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>
This commit is contained in:
4
internal/cache/cache.go
vendored
4
internal/cache/cache.go
vendored
@@ -94,6 +94,8 @@ func (c *Caches) Init() {
|
||||
c.initToken()
|
||||
c.initTombstone()
|
||||
c.initUser()
|
||||
c.initUserMute()
|
||||
c.initUserMuteIDs()
|
||||
c.initWebfinger()
|
||||
c.initVisibility()
|
||||
}
|
||||
@@ -164,5 +166,7 @@ func (c *Caches) Sweep(threshold float64) {
|
||||
c.GTS.Token.Trim(threshold)
|
||||
c.GTS.Tombstone.Trim(threshold)
|
||||
c.GTS.User.Trim(threshold)
|
||||
c.GTS.UserMute.Trim(threshold)
|
||||
c.GTS.UserMuteIDs.Trim(threshold)
|
||||
c.Visibility.Trim(threshold)
|
||||
}
|
||||
|
53
internal/cache/db.go
vendored
53
internal/cache/db.go
vendored
@@ -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(
|
||||
|
5
internal/cache/invalidate.go
vendored
5
internal/cache/invalidate.go
vendored
@@ -213,3 +213,8 @@ func (c *Caches) OnInvalidateUser(user *gtsmodel.User) {
|
||||
c.Visibility.Invalidate("ItemID", user.AccountID)
|
||||
c.Visibility.Invalidate("RequesterID", user.AccountID)
|
||||
}
|
||||
|
||||
func (c *Caches) OnInvalidateUserMute(mute *gtsmodel.UserMute) {
|
||||
// Invalidate source account's user mute lists.
|
||||
c.GTS.UserMuteIDs.Invalidate(mute.AccountID)
|
||||
}
|
||||
|
12
internal/cache/size.go
vendored
12
internal/cache/size.go
vendored
@@ -715,3 +715,15 @@ func sizeofUser() uintptr {
|
||||
ExternalID: exampleID,
|
||||
}))
|
||||
}
|
||||
|
||||
func sizeofUserMute() uintptr {
|
||||
return uintptr(size.Of(>smodel.UserMute{
|
||||
ID: exampleID,
|
||||
CreatedAt: exampleTime,
|
||||
UpdatedAt: exampleTime,
|
||||
ExpiresAt: exampleTime,
|
||||
AccountID: exampleID,
|
||||
TargetAccountID: exampleID,
|
||||
Notifications: util.Ptr(false),
|
||||
}))
|
||||
}
|
||||
|
Reference in New Issue
Block a user