diff options
| author | 2025-07-01 16:00:04 +0200 | |
|---|---|---|
| committer | 2025-07-01 16:00:04 +0200 | |
| commit | 4f2aa792b33fdd5fb4b22dec813b3668d7190522 (patch) | |
| tree | 1148a9322d04bf43c1c159df3079fb1790c5c154 /internal/processing/filters/common | |
| parent | [chore] update go dependencies (#4304) (diff) | |
| download | gotosocial-4f2aa792b33fdd5fb4b22dec813b3668d7190522.tar.xz | |
[performance] add statusfilter cache to cache calculated status filtering results (#4303)
this adds another 'filter' type cache, similar to the visibility and mute caches, to cache the results of status filtering checks. for the moment this keeps all the check calls themselves within the frontend typeconversion code, but i may move this out of the typeconverter in a future PR (also removing the ErrHideStatus means of propagating a hidden status).
also tweaks some of the cache invalidation hooks to not make unnecessary calls.
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4303
Co-authored-by: kim <grufwub@gmail.com>
Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/processing/filters/common')
| -rw-r--r-- | internal/processing/filters/common/common.go | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/internal/processing/filters/common/common.go b/internal/processing/filters/common/common.go index a119d3bd4..8930b3aaf 100644 --- a/internal/processing/filters/common/common.go +++ b/internal/processing/filters/common/common.go @@ -28,12 +28,19 @@ import ( "code.superseriousbusiness.org/gotosocial/internal/gtscontext" "code.superseriousbusiness.org/gotosocial/internal/gtserror" "code.superseriousbusiness.org/gotosocial/internal/gtsmodel" + "code.superseriousbusiness.org/gotosocial/internal/log" + "code.superseriousbusiness.org/gotosocial/internal/processing/stream" "code.superseriousbusiness.org/gotosocial/internal/state" ) -type Processor struct{ state *state.State } +type Processor struct { + state *state.State + stream *stream.Processor +} -func New(state *state.State) *Processor { return &Processor{state} } +func New(state *state.State, stream *stream.Processor) *Processor { + return &Processor{state, stream} +} // CheckFilterExists calls .GetFilter() with a barebones context to not // fetch any sub-models, and not returning the result. this functionally @@ -160,6 +167,27 @@ func (p *Processor) GetFilterKeyword( return keyword, filter, nil } +// OnFilterChanged ... +func (p *Processor) OnFilterChanged(ctx context.Context, requester *gtsmodel.Account) { + + // Get list of list IDs created by this requesting account. + listIDs, err := p.state.DB.GetListIDsByAccountID(ctx, requester.ID) + if err != nil { + log.Errorf(ctx, "error getting account '%s' lists: %v", requester.Username, err) + } + + // Unprepare this requester's home timeline. + p.state.Caches.Timelines.Home.Unprepare(requester.ID) + + // Unprepare list timelines. + for _, id := range listIDs { + p.state.Caches.Timelines.List.Unprepare(id) + } + + // Send filter changed event for account. + p.stream.FiltersChanged(ctx, requester) +} + // FromAPIContexts converts a slice of frontend API model FilterContext types to our internal FilterContexts bit field. func FromAPIContexts(apiContexts []apimodel.FilterContext) (gtsmodel.FilterContexts, gtserror.WithCode) { var contexts gtsmodel.FilterContexts |
