mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[bugfix] use a much shorter refresh limit for statuses with polls (#2453)
* 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>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user