[performance] cache mute check results (#4202)

This separates our the user mute handling from the typeconverter code, and creates a new "mutes" filter type (in a similar vein to the visibility filter) subpkg with its own result cache. This is a heavy mix of both chore given that mute calculation shouldn't have been handled in the conversion to frontend API types, and a performance bonus since we don't need to load and calculate so many things each time, just the single result each time with all necessary invalidation handled by database cache hooks.

Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4202
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
This commit is contained in:
kim 2025-05-31 17:30:57 +02:00 committed by kim
commit faed35c938
65 changed files with 1645 additions and 766 deletions

View file

@ -22,6 +22,7 @@ import (
"code.superseriousbusiness.org/gotosocial/internal/email"
"code.superseriousbusiness.org/gotosocial/internal/federation"
"code.superseriousbusiness.org/gotosocial/internal/filter/interaction"
"code.superseriousbusiness.org/gotosocial/internal/filter/mutes"
"code.superseriousbusiness.org/gotosocial/internal/filter/visibility"
"code.superseriousbusiness.org/gotosocial/internal/media"
"code.superseriousbusiness.org/gotosocial/internal/processing"
@ -41,7 +42,6 @@ func NewTestProcessor(
webPushSender webpush.Sender,
mediaManager *media.Manager,
) *processing.Processor {
return processing.NewProcessor(
cleaner.New(state),
subscriptions.New(
@ -57,6 +57,7 @@ func NewTestProcessor(
emailSender,
webPushSender,
visibility.NewFilter(state),
mutes.NewFilter(state),
interaction.NewFilter(state),
)
}

View file

@ -22,6 +22,7 @@ import (
"code.superseriousbusiness.org/gotosocial/internal/cleaner"
"code.superseriousbusiness.org/gotosocial/internal/email"
"code.superseriousbusiness.org/gotosocial/internal/filter/interaction"
"code.superseriousbusiness.org/gotosocial/internal/filter/mutes"
"code.superseriousbusiness.org/gotosocial/internal/filter/visibility"
"code.superseriousbusiness.org/gotosocial/internal/processing"
"code.superseriousbusiness.org/gotosocial/internal/processing/common"
@ -67,6 +68,7 @@ func SetupTestStructs(
state.Storage = storage
typeconverter := typeutils.NewConverter(&state)
visFilter := visibility.NewFilter(&state)
muteFilter := mutes.NewFilter(&state)
intFilter := interaction.NewFilter(&state)
httpClient := NewMockHTTPClient(nil, rMediaPath)
@ -86,6 +88,7 @@ func SetupTestStructs(
typeconverter,
federator,
visFilter,
muteFilter,
)
processor := processing.NewProcessor(
@ -99,6 +102,7 @@ func SetupTestStructs(
emailSender,
webPushSender,
visFilter,
muteFilter,
intFilter,
)

View file

@ -20,7 +20,7 @@ package testrig
import (
"context"
"code.superseriousbusiness.org/gotosocial/internal/filter/usermute"
apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model"
"code.superseriousbusiness.org/gotosocial/internal/gtsmodel"
"code.superseriousbusiness.org/gotosocial/internal/webpush"
)
@ -39,11 +39,10 @@ func NewWebPushMockSender() *WebPushMockSender {
func (m *WebPushMockSender) Send(
ctx context.Context,
notification *gtsmodel.Notification,
filters []*gtsmodel.Filter,
mutes *usermute.CompiledUserMuteList,
notif *gtsmodel.Notification,
apiNotif *apimodel.Notification,
) error {
m.Sent[notification.TargetAccountID] = append(m.Sent[notification.TargetAccountID], notification)
m.Sent[notif.TargetAccountID] = append(m.Sent[notif.TargetAccountID], notif)
return nil
}
@ -57,9 +56,8 @@ func NewNoopWebPushSender() webpush.Sender {
func (n *noopWebPushSender) Send(
ctx context.Context,
notification *gtsmodel.Notification,
filters []*gtsmodel.Filter,
mutes *usermute.CompiledUserMuteList,
notif *gtsmodel.Notification,
apiNotif *apimodel.Notification,
) error {
return nil
}