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/timeline/timeline.go | 33 ++++++++++---------------------- 1 file changed, 10 insertions(+), 23 deletions(-) (limited to 'internal/processing/timeline/timeline.go') diff --git a/internal/processing/timeline/timeline.go b/internal/processing/timeline/timeline.go index 2eab57195..a86702d42 100644 --- a/internal/processing/timeline/timeline.go +++ b/internal/processing/timeline/timeline.go @@ -26,8 +26,8 @@ import ( apimodel "code.superseriousbusiness.org/gotosocial/internal/api/model" timelinepkg "code.superseriousbusiness.org/gotosocial/internal/cache/timeline" "code.superseriousbusiness.org/gotosocial/internal/db" + "code.superseriousbusiness.org/gotosocial/internal/filter/mutes" statusfilter "code.superseriousbusiness.org/gotosocial/internal/filter/status" - "code.superseriousbusiness.org/gotosocial/internal/filter/usermute" "code.superseriousbusiness.org/gotosocial/internal/filter/visibility" "code.superseriousbusiness.org/gotosocial/internal/gtserror" "code.superseriousbusiness.org/gotosocial/internal/gtsmodel" @@ -48,16 +48,18 @@ var ( ) type Processor struct { - state *state.State - converter *typeutils.Converter - visFilter *visibility.Filter + state *state.State + converter *typeutils.Converter + visFilter *visibility.Filter + muteFilter *mutes.Filter } -func New(state *state.State, converter *typeutils.Converter, visFilter *visibility.Filter) Processor { +func New(state *state.State, converter *typeutils.Converter, visFilter *visibility.Filter, muteFilter *mutes.Filter) Processor { return Processor{ - state: state, - converter: converter, - visFilter: visFilter, + state: state, + converter: converter, + visFilter: visFilter, + muteFilter: muteFilter, } } @@ -78,7 +80,6 @@ func (p *Processor) getStatusTimeline( ) { var err error var filters []*gtsmodel.Filter - var mutes *usermute.CompiledUserMuteList if requester != nil { // Fetch all filters relevant for requesting account. @@ -89,19 +90,6 @@ func (p *Processor) getStatusTimeline( err := gtserror.Newf("error getting account filters: %w", err) return nil, gtserror.NewErrorInternalError(err) } - - // Get a list of all account mutes for requester. - allMutes, err := p.state.DB.GetAccountMutes(ctx, - requester.ID, - nil, // i.e. all - ) - if err != nil && !errors.Is(err, db.ErrNoEntries) { - err := gtserror.Newf("error getting account mutes: %w", err) - return nil, gtserror.NewErrorInternalError(err) - } - - // Compile all account mutes to useable form. - mutes = usermute.NewCompiledUserMuteList(allMutes) } // Ensure we have valid @@ -148,7 +136,6 @@ func (p *Processor) getStatusTimeline( requester, filterCtx, filters, - mutes, ) if err != nil && !errors.Is(err, statusfilter.ErrHideStatus) { return nil, err -- cgit v1.2.3