mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 20:52:24 -05:00
don't return on status filter errors, these are usually transient
This commit is contained in:
parent
acba53a354
commit
c6df3f610d
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
|
// filter can be used to perform filtering of returned
|
||||||
// statuses BEFORE insert into cache. i.e. this will effect
|
// statuses BEFORE insert into cache. i.e. this will effect
|
||||||
// what actually gets stored in the timeline cache.
|
// 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,
|
n int,
|
||||||
err error,
|
err error,
|
||||||
|
|
@ -218,7 +218,7 @@ func (t *StatusTimeline) preload(
|
||||||
// filter can be used to perform filtering of returned
|
// filter can be used to perform filtering of returned
|
||||||
// statuses BEFORE insert into cache. i.e. this will effect
|
// statuses BEFORE insert into cache. i.e. this will effect
|
||||||
// what actually gets stored in the timeline cache.
|
// 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) {
|
) (int, error) {
|
||||||
if loadPage == nil {
|
if loadPage == nil {
|
||||||
panic("nil load page func")
|
panic("nil load page func")
|
||||||
|
|
@ -259,10 +259,7 @@ func (t *StatusTimeline) preload(
|
||||||
page.Max.Value = statuses[len(statuses)-1].ID
|
page.Max.Value = statuses[len(statuses)-1].ID
|
||||||
|
|
||||||
// Perform any filtering on newly loaded statuses.
|
// Perform any filtering on newly loaded statuses.
|
||||||
statuses, err = doStatusFilter(statuses, filter)
|
statuses = doStatusFilter(statuses, filter)
|
||||||
if err != nil {
|
|
||||||
return n, gtserror.Newf("error filtering statuses: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// After filtering no more
|
// After filtering no more
|
||||||
// statuses remain, retry.
|
// statuses remain, retry.
|
||||||
|
|
@ -320,8 +317,8 @@ func (t *StatusTimeline) Load(
|
||||||
// to load status models of already cached entries in the timeline.
|
// to load status models of already cached entries in the timeline.
|
||||||
loadIDs func(ids []string) (statuses []*gtsmodel.Status, err error),
|
loadIDs func(ids []string) (statuses []*gtsmodel.Status, err error),
|
||||||
|
|
||||||
// filter can be used to perform filtering of returned statuses.
|
// filter performs filtering of returned statuses.
|
||||||
filter func(each *gtsmodel.Status) (delete bool, err error),
|
filter func(each *gtsmodel.Status) (delete bool),
|
||||||
|
|
||||||
// prepareAPI should prepare internal status model to frontend API model.
|
// prepareAPI should prepare internal status model to frontend API model.
|
||||||
prepareAPI func(status *gtsmodel.Status) (apiStatus *apimodel.Status, err error),
|
prepareAPI func(status *gtsmodel.Status) (apiStatus *apimodel.Status, err error),
|
||||||
|
|
@ -447,7 +444,7 @@ func loadStatusTimeline(
|
||||||
metas []*StatusMeta,
|
metas []*StatusMeta,
|
||||||
apiStatuses []*apimodel.Status,
|
apiStatuses []*apimodel.Status,
|
||||||
loadPage func(page *paging.Page) (statuses []*gtsmodel.Status, err error),
|
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),
|
prepareAPI func(status *gtsmodel.Status) (apiStatus *apimodel.Status, err error),
|
||||||
) (
|
) (
|
||||||
[]*apimodel.Status,
|
[]*apimodel.Status,
|
||||||
|
|
@ -504,10 +501,7 @@ func loadStatusTimeline(
|
||||||
nextPageParams(nextPg, statuses[len(statuses)-1].ID, order)
|
nextPageParams(nextPg, statuses[len(statuses)-1].ID, order)
|
||||||
|
|
||||||
// Perform any filtering on newly loaded statuses.
|
// Perform any filtering on newly loaded statuses.
|
||||||
statuses, err = doStatusFilter(statuses, filter)
|
statuses = doStatusFilter(statuses, filter)
|
||||||
if err != nil {
|
|
||||||
return nil, "", "", gtserror.Newf("error filtering statuses: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// After filtering no more
|
// After filtering no more
|
||||||
// statuses remain, retry.
|
// statuses remain, retry.
|
||||||
|
|
@ -829,34 +823,14 @@ func toStatusMeta(in []*StatusMeta, statuses []*gtsmodel.Status) []*StatusMeta {
|
||||||
}
|
}
|
||||||
|
|
||||||
// doStatusFilter performs given filter function on provided statuses,
|
// 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) []*gtsmodel.Status {
|
||||||
func doStatusFilter(statuses []*gtsmodel.Status, filter func(*gtsmodel.Status) (bool, error)) ([]*gtsmodel.Status, error) {
|
|
||||||
|
|
||||||
// Check for provided
|
// Check for provided
|
||||||
// filter function.
|
// filter function.
|
||||||
if filter == nil {
|
if filter == nil {
|
||||||
return statuses, nil
|
return statuses
|
||||||
}
|
}
|
||||||
|
|
||||||
// Iterate through input statuses.
|
// Filter the provided input statuses.
|
||||||
for i := 0; i < len(statuses); {
|
return slices.DeleteFunc(statuses, filter)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
statusfilter "github.com/superseriousbusiness/gotosocial/internal/filter/status"
|
statusfilter "github.com/superseriousbusiness/gotosocial/internal/filter/status"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -83,11 +84,14 @@ func (p *Processor) HomeTimelineGet(
|
||||||
|
|
||||||
// Pre-filtering function,
|
// Pre-filtering function,
|
||||||
// i.e. filter before caching.
|
// 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.
|
// Check the visibility of passed status to requesting user.
|
||||||
ok, err := p.visFilter.StatusHomeTimelineable(ctx, requester, s)
|
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/gtscontext"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -96,11 +97,14 @@ func (p *Processor) ListTimelineGet(
|
||||||
|
|
||||||
// Filtering function,
|
// Filtering function,
|
||||||
// i.e. filter before caching.
|
// 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.
|
// Check the visibility of passed status to requesting user.
|
||||||
ok, err := p.visFilter.StatusHomeTimelineable(ctx, requester, s)
|
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"
|
statusfilter "github.com/superseriousbusiness/gotosocial/internal/filter/status"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -87,11 +88,14 @@ func (p *Processor) publicTimelineGet(
|
||||||
|
|
||||||
// Pre-filtering function,
|
// Pre-filtering function,
|
||||||
// i.e. filter before caching.
|
// 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.
|
// Check the visibility of passed status to requesting user.
|
||||||
ok, err := p.visFilter.StatusPublicTimelineable(ctx, requester, s)
|
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,
|
// Filtering function,
|
||||||
// i.e. filter before caching.
|
// 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.
|
// Check the visibility of passed status to requesting user.
|
||||||
ok, err := p.visFilter.StatusPublicTimelineable(ctx, requester, s)
|
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"
|
statusfilter "github.com/superseriousbusiness/gotosocial/internal/filter/status"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
|
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
"github.com/superseriousbusiness/gotosocial/internal/paging"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/text"
|
"github.com/superseriousbusiness/gotosocial/internal/text"
|
||||||
)
|
)
|
||||||
|
|
@ -95,11 +96,14 @@ func (p *Processor) TagTimelineGet(
|
||||||
|
|
||||||
// Filtering function,
|
// Filtering function,
|
||||||
// i.e. filter before caching.
|
// 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.
|
// Check the visibility of passed status to requesting user.
|
||||||
ok, err := p.visFilter.StatusHomeTimelineable(ctx, requester, s)
|
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,
|
pageQuery url.Values,
|
||||||
filterCtx statusfilter.FilterContext,
|
filterCtx statusfilter.FilterContext,
|
||||||
loadPage func(*paging.Page) (statuses []*gtsmodel.Status, err error),
|
loadPage func(*paging.Page) (statuses []*gtsmodel.Status, err error),
|
||||||
filter func(*gtsmodel.Status) (bool, error),
|
filter func(*gtsmodel.Status) (delete bool),
|
||||||
) (
|
) (
|
||||||
*apimodel.PageableResponse,
|
*apimodel.PageableResponse,
|
||||||
gtserror.WithCode,
|
gtserror.WithCode,
|
||||||
|
|
@ -80,7 +80,6 @@ func (p *Processor) getStatusTimeline(
|
||||||
var mutes *usermute.CompiledUserMuteList
|
var mutes *usermute.CompiledUserMuteList
|
||||||
|
|
||||||
if requester != nil {
|
if requester != nil {
|
||||||
|
|
||||||
// Fetch all filters relevant for requesting account.
|
// Fetch all filters relevant for requesting account.
|
||||||
filters, err = p.state.DB.GetFiltersForAccountID(ctx,
|
filters, err = p.state.DB.GetFiltersForAccountID(ctx,
|
||||||
requester.ID,
|
requester.ID,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue