diff --git a/internal/cache/timeline/status.go b/internal/cache/timeline/status.go index 9f0af9cdc..750d2b2f1 100644 --- a/internal/cache/timeline/status.go +++ b/internal/cache/timeline/status.go @@ -191,7 +191,7 @@ func (t *StatusTimeline) Preload( // filter can be used to perform filtering of returned // statuses BEFORE insert into cache. i.e. this will effect // what actually gets stored in the timeline cache. - filter func(each *gtsmodel.Status) (delete bool, err error), + filter func(each *gtsmodel.Status) (delete bool), ) ( n int, err error, @@ -218,7 +218,7 @@ func (t *StatusTimeline) preload( // filter can be used to perform filtering of returned // statuses BEFORE insert into cache. i.e. this will effect // what actually gets stored in the timeline cache. - filter func(each *gtsmodel.Status) (delete bool, err error), + filter func(each *gtsmodel.Status) (delete bool), ) (int, error) { if loadPage == nil { panic("nil load page func") @@ -259,10 +259,7 @@ func (t *StatusTimeline) preload( page.Max.Value = statuses[len(statuses)-1].ID // Perform any filtering on newly loaded statuses. - statuses, err = doStatusFilter(statuses, filter) - if err != nil { - return n, gtserror.Newf("error filtering statuses: %w", err) - } + statuses = doStatusFilter(statuses, filter) // After filtering no more // statuses remain, retry. @@ -320,8 +317,8 @@ func (t *StatusTimeline) Load( // to load status models of already cached entries in the timeline. loadIDs func(ids []string) (statuses []*gtsmodel.Status, err error), - // filter can be used to perform filtering of returned statuses. - filter func(each *gtsmodel.Status) (delete bool, err error), + // filter performs filtering of returned statuses. + filter func(each *gtsmodel.Status) (delete bool), // prepareAPI should prepare internal status model to frontend API model. prepareAPI func(status *gtsmodel.Status) (apiStatus *apimodel.Status, err error), @@ -447,7 +444,7 @@ func loadStatusTimeline( metas []*StatusMeta, apiStatuses []*apimodel.Status, loadPage func(page *paging.Page) (statuses []*gtsmodel.Status, err error), - filter func(each *gtsmodel.Status) (delete bool, err error), + filter func(each *gtsmodel.Status) (delete bool), prepareAPI func(status *gtsmodel.Status) (apiStatus *apimodel.Status, err error), ) ( []*apimodel.Status, @@ -504,10 +501,7 @@ func loadStatusTimeline( nextPageParams(nextPg, statuses[len(statuses)-1].ID, order) // Perform any filtering on newly loaded statuses. - statuses, err = doStatusFilter(statuses, filter) - if err != nil { - return nil, "", "", gtserror.Newf("error filtering statuses: %w", err) - } + statuses = doStatusFilter(statuses, filter) // After filtering no more // statuses remain, retry. @@ -829,34 +823,14 @@ func toStatusMeta(in []*StatusMeta, statuses []*gtsmodel.Status) []*StatusMeta { } // doStatusFilter performs given filter function on provided statuses, -// returning early if an error is returned. returns filtered statuses. -func doStatusFilter(statuses []*gtsmodel.Status, filter func(*gtsmodel.Status) (bool, error)) ([]*gtsmodel.Status, error) { +func doStatusFilter(statuses []*gtsmodel.Status, filter func(*gtsmodel.Status) bool) []*gtsmodel.Status { // Check for provided // filter function. if filter == nil { - return statuses, nil + return statuses } - // Iterate through input statuses. - for i := 0; i < len(statuses); { - status := statuses[i] - - // Pass through filter func. - ok, err := filter(status) - if err != nil { - return nil, err - } - - if ok { - // Delete this status from input slice. - statuses = slices.Delete(statuses, i, i+1) - continue - } - - // Iter. - i++ - } - - return statuses, nil + // Filter the provided input statuses. + return slices.DeleteFunc(statuses, filter) } diff --git a/internal/processing/timeline/home.go b/internal/processing/timeline/home.go index a2e9e8bc8..bfefb5bb5 100644 --- a/internal/processing/timeline/home.go +++ b/internal/processing/timeline/home.go @@ -25,6 +25,7 @@ import ( statusfilter "github.com/superseriousbusiness/gotosocial/internal/filter/status" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" + "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/superseriousbusiness/gotosocial/internal/paging" ) @@ -83,11 +84,14 @@ func (p *Processor) HomeTimelineGet( // Pre-filtering function, // i.e. filter before caching. - func(s *gtsmodel.Status) (bool, error) { + func(s *gtsmodel.Status) bool { // Check the visibility of passed status to requesting user. ok, err := p.visFilter.StatusHomeTimelineable(ctx, requester, s) - return !ok, err + if err != nil { + log.Errorf(ctx, "error filtering status %s: %v", s.URI, err) + } + return !ok }, ) } diff --git a/internal/processing/timeline/list.go b/internal/processing/timeline/list.go index 8452e7ba8..18be9e23f 100644 --- a/internal/processing/timeline/list.go +++ b/internal/processing/timeline/list.go @@ -27,6 +27,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/gtscontext" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" + "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/superseriousbusiness/gotosocial/internal/paging" ) @@ -96,11 +97,14 @@ func (p *Processor) ListTimelineGet( // Filtering function, // i.e. filter before caching. - func(s *gtsmodel.Status) (bool, error) { + func(s *gtsmodel.Status) bool { // Check the visibility of passed status to requesting user. ok, err := p.visFilter.StatusHomeTimelineable(ctx, requester, s) - return !ok, err + if err != nil { + log.Errorf(ctx, "error filtering status %s: %v", s.URI, err) + } + return !ok }, ) } diff --git a/internal/processing/timeline/public.go b/internal/processing/timeline/public.go index 18c738e7c..e30cf1ec7 100644 --- a/internal/processing/timeline/public.go +++ b/internal/processing/timeline/public.go @@ -24,6 +24,7 @@ import ( statusfilter "github.com/superseriousbusiness/gotosocial/internal/filter/status" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" + "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/superseriousbusiness/gotosocial/internal/paging" ) @@ -87,11 +88,14 @@ func (p *Processor) publicTimelineGet( // Pre-filtering function, // i.e. filter before caching. - func(s *gtsmodel.Status) (bool, error) { + func(s *gtsmodel.Status) bool { // Check the visibility of passed status to requesting user. ok, err := p.visFilter.StatusPublicTimelineable(ctx, requester, s) - return !ok, err + if err != nil { + log.Errorf(ctx, "error filtering status %s: %v", s.URI, err) + } + return !ok }, ) } @@ -136,11 +140,14 @@ func (p *Processor) localTimelineGet( // Filtering function, // i.e. filter before caching. - func(s *gtsmodel.Status) (bool, error) { + func(s *gtsmodel.Status) bool { // Check the visibility of passed status to requesting user. ok, err := p.visFilter.StatusPublicTimelineable(ctx, requester, s) - return !ok, err + if err != nil { + log.Errorf(ctx, "error filtering status %s: %v", s.URI, err) + } + return !ok }, ) } diff --git a/internal/processing/timeline/tag.go b/internal/processing/timeline/tag.go index 8169843e1..008ea11d8 100644 --- a/internal/processing/timeline/tag.go +++ b/internal/processing/timeline/tag.go @@ -27,6 +27,7 @@ import ( statusfilter "github.com/superseriousbusiness/gotosocial/internal/filter/status" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" + "github.com/superseriousbusiness/gotosocial/internal/log" "github.com/superseriousbusiness/gotosocial/internal/paging" "github.com/superseriousbusiness/gotosocial/internal/text" ) @@ -95,11 +96,14 @@ func (p *Processor) TagTimelineGet( // Filtering function, // i.e. filter before caching. - func(s *gtsmodel.Status) (bool, error) { + func(s *gtsmodel.Status) bool { // Check the visibility of passed status to requesting user. ok, err := p.visFilter.StatusHomeTimelineable(ctx, requester, s) - return !ok, err + if err != nil { + log.Errorf(ctx, "error filtering status %s: %v", s.URI, err) + } + return !ok }, ) } diff --git a/internal/processing/timeline/timeline.go b/internal/processing/timeline/timeline.go index 7e2b958d1..7a49e58f2 100644 --- a/internal/processing/timeline/timeline.go +++ b/internal/processing/timeline/timeline.go @@ -70,7 +70,7 @@ func (p *Processor) getStatusTimeline( pageQuery url.Values, filterCtx statusfilter.FilterContext, loadPage func(*paging.Page) (statuses []*gtsmodel.Status, err error), - filter func(*gtsmodel.Status) (bool, error), + filter func(*gtsmodel.Status) (delete bool), ) ( *apimodel.PageableResponse, gtserror.WithCode, @@ -80,7 +80,6 @@ func (p *Processor) getStatusTimeline( var mutes *usermute.CompiledUserMuteList if requester != nil { - // Fetch all filters relevant for requesting account. filters, err = p.state.DB.GetFiltersForAccountID(ctx, requester.ID,