From faed35c9388bc28ea0fdfe3aae3b489ca952c006 Mon Sep 17 00:00:00 2001 From: kim Date: Sat, 31 May 2025 17:30:57 +0200 Subject: [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 Co-committed-by: kim --- internal/processing/common/status.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'internal/processing/common/status.go') diff --git a/internal/processing/common/status.go b/internal/processing/common/status.go index 14245f88a..441a58384 100644 --- a/internal/processing/common/status.go +++ b/internal/processing/common/status.go @@ -25,7 +25,6 @@ import ( "code.superseriousbusiness.org/gotosocial/internal/db" "code.superseriousbusiness.org/gotosocial/internal/federation/dereferencing" statusfilter "code.superseriousbusiness.org/gotosocial/internal/filter/status" - "code.superseriousbusiness.org/gotosocial/internal/filter/usermute" "code.superseriousbusiness.org/gotosocial/internal/gtserror" "code.superseriousbusiness.org/gotosocial/internal/gtsmodel" "code.superseriousbusiness.org/gotosocial/internal/log" @@ -216,7 +215,6 @@ func (p *Processor) GetAPIStatus( requester, statusfilter.FilterContextNone, nil, - nil, ) if err != nil { err := gtserror.Newf("error converting: %w", err) @@ -238,7 +236,6 @@ func (p *Processor) GetVisibleAPIStatuses( statuses []*gtsmodel.Status, filterContext statusfilter.FilterContext, filters []*gtsmodel.Filter, - userMutes []*gtsmodel.UserMute, ) []apimodel.Status { // Start new log entry with @@ -247,9 +244,6 @@ func (p *Processor) GetVisibleAPIStatuses( l := log.WithContext(ctx). WithField("caller", log.Caller(3)) - // Compile mutes to useable user mutes for type converter. - compUserMutes := usermute.NewCompiledUserMuteList(userMutes) - // Iterate filtered statuses for conversion to API model. apiStatuses := make([]apimodel.Status, 0, len(statuses)) for _, status := range statuses { @@ -268,13 +262,23 @@ func (p *Processor) GetVisibleAPIStatuses( continue } + // Check whether this status is muted by requesting account. + muted, err := p.muteFilter.StatusMuted(ctx, requester, status) + if err != nil { + log.Errorf(ctx, "error checking mute: %v", err) + continue + } + + if muted { + continue + } + // Convert to API status, taking mute / filter into account. apiStatus, err := p.converter.StatusToAPIStatus(ctx, status, requester, filterContext, filters, - compUserMutes, ) if err != nil && !errors.Is(err, statusfilter.ErrHideStatus) { l.Errorf("error converting: %v", err) -- cgit v1.2.3