diff options
Diffstat (limited to 'internal/processing')
-rw-r--r-- | internal/processing/common/account.go (renamed from internal/processing/common/account.go.go) | 2 | ||||
-rw-r--r-- | internal/processing/common/status.go | 39 | ||||
-rw-r--r-- | internal/processing/fedi/status.go | 2 | ||||
-rw-r--r-- | internal/processing/polls/poll.go | 2 | ||||
-rw-r--r-- | internal/processing/status/bookmark.go | 2 | ||||
-rw-r--r-- | internal/processing/status/boost.go | 4 | ||||
-rw-r--r-- | internal/processing/status/fave.go | 4 | ||||
-rw-r--r-- | internal/processing/status/get.go | 6 | ||||
-rw-r--r-- | internal/processing/status/mute.go | 2 | ||||
-rw-r--r-- | internal/processing/status/pin.go | 2 | ||||
-rw-r--r-- | internal/processing/workers/fromfediapi.go | 11 |
11 files changed, 47 insertions, 29 deletions
diff --git a/internal/processing/common/account.go.go b/internal/processing/common/account.go index f4bd06e76..9a39ea26d 100644 --- a/internal/processing/common/account.go.go +++ b/internal/processing/common/account.go @@ -66,7 +66,7 @@ func (p *Processor) GetTargetAccountBy( requester.Username, target, nil, - false, + nil, ) } diff --git a/internal/processing/common/status.go b/internal/processing/common/status.go index ae03a5306..308f5173f 100644 --- a/internal/processing/common/status.go +++ b/internal/processing/common/status.go @@ -23,19 +23,24 @@ import ( apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/db" + "github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/log" ) -// GetTargetStatusBy fetches the target status with db load function, given the authorized (or, nil) requester's -// account. This returns an approprate gtserror.WithCode accounting for not found and visibility to requester. -// The refresh argument allows specifying whether the returned copy should be force refreshed. +// GetTargetStatusBy fetches the target status with db load +// function, given the authorized (or, nil) requester's +// account. This returns an approprate gtserror.WithCode +// accounting for not found and visibility to requester. +// +// window can be used to force refresh of the target if it's +// deemed to be stale. Falls back to default window if nil. func (p *Processor) GetTargetStatusBy( ctx context.Context, requester *gtsmodel.Account, getTargetFromDB func() (*gtsmodel.Status, error), - refresh bool, + window *dereferencing.FreshnessWindow, ) ( status *gtsmodel.Status, visible bool, @@ -68,13 +73,15 @@ func (p *Processor) GetTargetStatusBy( // a requester (i.e. request is authorized) // to prevent a possible DOS vector. - if refresh { - // Refresh required, forcibly do synchronously. + if window != nil { + // Window is explicitly set, so likely + // tighter than the default window. + // Do refresh synchronously. _, _, err := p.federator.RefreshStatus(ctx, requester.Username, target, nil, - true, // force + window, ) if err != nil { log.Errorf(ctx, "error refreshing status: %v", err) @@ -85,7 +92,7 @@ func (p *Processor) GetTargetStatusBy( requester.Username, target, nil, - false, // force + nil, ) } } @@ -95,11 +102,14 @@ func (p *Processor) GetTargetStatusBy( // GetVisibleTargetStatus calls GetTargetStatusBy(), // but converts a non-visible result to not-found error. +// +// window can be used to force refresh of the target if it's +// deemed to be stale. Falls back to default window if nil. func (p *Processor) GetVisibleTargetStatusBy( ctx context.Context, requester *gtsmodel.Account, getTargetFromDB func() (*gtsmodel.Status, error), - refresh bool, + window *dereferencing.FreshnessWindow, ) ( status *gtsmodel.Status, errWithCode gtserror.WithCode, @@ -108,7 +118,7 @@ func (p *Processor) GetVisibleTargetStatusBy( target, visible, errWithCode := p.GetTargetStatusBy(ctx, requester, getTargetFromDB, - refresh, + window, ) if errWithCode != nil { return nil, errWithCode @@ -128,18 +138,21 @@ func (p *Processor) GetVisibleTargetStatusBy( // GetVisibleTargetStatus calls GetVisibleTargetStatusBy(), // passing in a database function that fetches by status ID. +// +// window can be used to force refresh of the target if it's +// deemed to be stale. Falls back to default window if nil. func (p *Processor) GetVisibleTargetStatus( ctx context.Context, requester *gtsmodel.Account, targetID string, - refresh bool, + window *dereferencing.FreshnessWindow, ) ( status *gtsmodel.Status, errWithCode gtserror.WithCode, ) { return p.GetVisibleTargetStatusBy(ctx, requester, func() (*gtsmodel.Status, error) { return p.state.DB.GetStatusByID(ctx, targetID) - }, refresh) + }, window) } // UnwrapIfBoost "unwraps" the given status if @@ -158,7 +171,7 @@ func (p *Processor) UnwrapIfBoost( return p.GetVisibleTargetStatus(ctx, requester, status.BoostOfID, - false, + nil, ) } diff --git a/internal/processing/fedi/status.go b/internal/processing/fedi/status.go index 2674ebf68..2849d08a4 100644 --- a/internal/processing/fedi/status.go +++ b/internal/processing/fedi/status.go @@ -100,7 +100,7 @@ func (p *Processor) StatusRepliesGet( status, errWithCode := p.c.GetVisibleTargetStatus(ctx, requester, statusID, - false, // refresh + nil, // default freshness ) if errWithCode != nil { return nil, errWithCode diff --git a/internal/processing/polls/poll.go b/internal/processing/polls/poll.go index 19cf555e5..fe8fc71c5 100644 --- a/internal/processing/polls/poll.go +++ b/internal/processing/polls/poll.go @@ -53,7 +53,7 @@ func (p *Processor) getTargetPoll(ctx context.Context, requester *gtsmodel.Accou func() (*gtsmodel.Status, error) { return p.state.DB.GetStatusByPollID(ctx, targetID) }, - true, // refresh + nil, // default freshness ) if errWithCode != nil { return nil, errWithCode diff --git a/internal/processing/status/bookmark.go b/internal/processing/status/bookmark.go index 224445838..778492c71 100644 --- a/internal/processing/status/bookmark.go +++ b/internal/processing/status/bookmark.go @@ -33,7 +33,7 @@ func (p *Processor) getBookmarkableStatus(ctx context.Context, requestingAccount targetStatus, errWithCode := p.c.GetVisibleTargetStatus(ctx, requestingAccount, targetStatusID, - false, // refresh + nil, // default freshness ) if errWithCode != nil { return nil, "", errWithCode diff --git a/internal/processing/status/boost.go b/internal/processing/status/boost.go index 2fc96091e..5fae695fd 100644 --- a/internal/processing/status/boost.go +++ b/internal/processing/status/boost.go @@ -43,7 +43,7 @@ func (p *Processor) BoostCreate( ctx, requester, targetID, - false, // refresh + nil, // default freshness ) if errWithCode != nil { return nil, errWithCode @@ -113,7 +113,7 @@ func (p *Processor) BoostRemove( ctx, requester, targetID, - false, // refresh + nil, // default freshness ) if errWithCode != nil { return nil, errWithCode diff --git a/internal/processing/status/fave.go b/internal/processing/status/fave.go index 7ac270e8c..7b71725ab 100644 --- a/internal/processing/status/fave.go +++ b/internal/processing/status/fave.go @@ -47,7 +47,7 @@ func (p *Processor) getFaveableStatus( ctx, requester, targetID, - false, // refresh + nil, // default freshness ) if errWithCode != nil { return nil, nil, errWithCode @@ -153,7 +153,7 @@ func (p *Processor) FavedBy(ctx context.Context, requestingAccount *gtsmodel.Acc targetStatus, errWithCode := p.c.GetVisibleTargetStatus(ctx, requestingAccount, targetStatusID, - false, // refresh + nil, // default freshness ) if errWithCode != nil { return nil, errWithCode diff --git a/internal/processing/status/get.go b/internal/processing/status/get.go index 7c275acbd..475ab0128 100644 --- a/internal/processing/status/get.go +++ b/internal/processing/status/get.go @@ -32,7 +32,7 @@ func (p *Processor) Get(ctx context.Context, requestingAccount *gtsmodel.Account targetStatus, errWithCode := p.c.GetVisibleTargetStatus(ctx, requestingAccount, targetStatusID, - false, // refresh + nil, // default freshness ) if errWithCode != nil { return nil, errWithCode @@ -46,7 +46,7 @@ func (p *Processor) WebGet(ctx context.Context, targetStatusID string) (*apimode targetStatus, errWithCode := p.c.GetVisibleTargetStatus(ctx, nil, // requester targetStatusID, - false, // refresh + nil, // default freshness ) if errWithCode != nil { return nil, errWithCode @@ -69,7 +69,7 @@ func (p *Processor) contextGet( targetStatus, errWithCode := p.c.GetVisibleTargetStatus(ctx, requestingAccount, targetStatusID, - false, // refresh + nil, // default freshness ) if errWithCode != nil { return nil, errWithCode diff --git a/internal/processing/status/mute.go b/internal/processing/status/mute.go index fb4f3b384..8888b59d4 100644 --- a/internal/processing/status/mute.go +++ b/internal/processing/status/mute.go @@ -44,7 +44,7 @@ func (p *Processor) getMuteableStatus( targetStatus, errWithCode := p.c.GetVisibleTargetStatus(ctx, requestingAccount, targetStatusID, - false, // refresh + nil, // default freshness ) if errWithCode != nil { return nil, errWithCode diff --git a/internal/processing/status/pin.go b/internal/processing/status/pin.go index f08b9652c..9a4a4b266 100644 --- a/internal/processing/status/pin.go +++ b/internal/processing/status/pin.go @@ -42,7 +42,7 @@ func (p *Processor) getPinnableStatus(ctx context.Context, requestingAccount *gt targetStatus, errWithCode := p.c.GetVisibleTargetStatus(ctx, requestingAccount, targetStatusID, - false, // refresh + nil, // default freshness ) if errWithCode != nil { return nil, errWithCode diff --git a/internal/processing/workers/fromfediapi.go b/internal/processing/workers/fromfediapi.go index 6dd4e543d..74ec0db25 100644 --- a/internal/processing/workers/fromfediapi.go +++ b/internal/processing/workers/fromfediapi.go @@ -23,6 +23,8 @@ import ( "codeberg.org/gruf/go-kv" "codeberg.org/gruf/go-logger/v2/level" "github.com/superseriousbusiness/gotosocial/internal/ap" + "github.com/superseriousbusiness/gotosocial/internal/federation/dereferencing" + "github.com/superseriousbusiness/gotosocial/internal/gtscontext" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" @@ -179,7 +181,8 @@ func (p *fediAPI) CreateStatus(ctx context.Context, fMsg messages.FromFediAPI) e fMsg.ReceivingAccount.Username, bareStatus, statusable, - true, + // Force refresh within 5min window. + dereferencing.Fresh, ) if err != nil { return gtserror.Newf("error processing new status %s: %w", bareStatus.URI, err) @@ -487,7 +490,8 @@ func (p *fediAPI) UpdateAccount(ctx context.Context, fMsg messages.FromFediAPI) fMsg.ReceivingAccount.Username, account, apubAcc, - true, // Force refresh. + // Force refresh within 5min window. + dereferencing.Fresh, ) if err != nil { log.Errorf(ctx, "error refreshing account: %v", err) @@ -512,7 +516,8 @@ func (p *fediAPI) UpdateStatus(ctx context.Context, fMsg messages.FromFediAPI) e fMsg.ReceivingAccount.Username, existing, apStatus, - true, + // Force refresh within 5min window. + dereferencing.Fresh, ) if err != nil { log.Errorf(ctx, "error refreshing status: %v", err) |