diff options
author | 2023-12-15 14:24:39 +0000 | |
---|---|---|
committer | 2023-12-15 15:24:39 +0100 | |
commit | f4fcffc8b56ef73c184ae17892b69181961c15c7 (patch) | |
tree | b678c44c9106e2ec8069dcf596a0554dee7410ab /internal/processing/polls/poll.go | |
parent | [bugfix] Let templates deref pointers, as a treat (#2448) (diff) | |
download | gotosocial-f4fcffc8b56ef73c184ae17892b69181961c15c7.tar.xz |
[bugfix] use a much shorter refresh limit for statuses with polls (#2453)v0.13.0
* specifically use a much shorter refresh limit for statuses with polls
* allow specifying whether status must be upToDate in calls to Get(Visible)?TargetStatusBy_(), limit force refresh to 5 minute cooldown
* remove the PollID check from statusUpToDate()
* remove unnecessary force flag checks
* remove unused field
* check refresh status error
* use argument name 'refresh' instead of 'upToDate' to better fit with the codebase
* add statuses_poll_id_idx
* remove the definitely-not copy-pasted comment i accidentally typed out in full
* only synchronously refresh if the refresh flag is provided, otherwise do async
* fix wrong force value being provided for async
---------
Co-authored-by: tobi <tobi.smethurst@protonmail.com>
Diffstat (limited to 'internal/processing/polls/poll.go')
-rw-r--r-- | internal/processing/polls/poll.go | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/internal/processing/polls/poll.go b/internal/processing/polls/poll.go index 3b258b76c..19cf555e5 100644 --- a/internal/processing/polls/poll.go +++ b/internal/processing/polls/poll.go @@ -19,11 +19,8 @@ package polls import ( "context" - "errors" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" - "github.com/superseriousbusiness/gotosocial/internal/db" - "github.com/superseriousbusiness/gotosocial/internal/gtscontext" "github.com/superseriousbusiness/gotosocial/internal/gtserror" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/processing/common" @@ -48,35 +45,24 @@ func New(common *common.Processor, state *state.State, converter *typeutils.Conv } // getTargetPoll fetches a target poll ID for requesting account, taking visibility of the poll's originating status into account. -func (p *Processor) getTargetPoll(ctx context.Context, requestingAccount *gtsmodel.Account, targetID string) (*gtsmodel.Poll, gtserror.WithCode) { - // Load the requested poll with ID. - // (barebones as we fetch status below) - poll, err := p.state.DB.GetPollByID( - gtscontext.SetBarebones(ctx), - targetID, +func (p *Processor) getTargetPoll(ctx context.Context, requester *gtsmodel.Account, targetID string) (*gtsmodel.Poll, gtserror.WithCode) { + // Load the status the poll is attached to by the poll ID, + // checking for visibility and ensuring it is up-to-date. + status, errWithCode := p.c.GetVisibleTargetStatusBy(ctx, + requester, + func() (*gtsmodel.Status, error) { + return p.state.DB.GetStatusByPollID(ctx, targetID) + }, + true, // refresh ) - if err != nil && !errors.Is(err, db.ErrNoEntries) { - return nil, gtserror.NewErrorInternalError(err) - } - - if poll == nil { - // No poll could be found for given ID. - const text = "target poll not found" - return nil, gtserror.NewErrorNotFound( - errors.New(text), - text, - ) - } - - // Check that we can see + fetch the originating status for requesting account. - status, errWithCode := p.c.GetVisibleTargetStatus(ctx, requestingAccount, poll.StatusID) if errWithCode != nil { return nil, errWithCode } - // Update poll status. + // Return most up-to-date + // copy of the status poll. + poll := status.Poll poll.Status = status - return poll, nil } |