mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-04-16 06:14:13 +00:00
don't return on status filter errors, these are usually transient
This commit is contained in:
parent
d75bbfee3b
commit
4e5414e546
6 changed files with 41 additions and 49 deletions
48
internal/cache/timeline/status.go
vendored
48
internal/cache/timeline/status.go
vendored
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue