[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:
kim 2023-12-15 14:24:39 +00:00 committed by GitHub
commit f4fcffc8b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 207 additions and 98 deletions

View file

@ -40,14 +40,25 @@ import (
// statusUpToDate returns whether the given status model is both updateable
// (i.e. remote status) and whether it needs an update based on `fetched_at`.
func statusUpToDate(status *gtsmodel.Status) bool {
func statusUpToDate(status *gtsmodel.Status, force bool) bool {
if *status.Local {
// Can't update local statuses.
return true
}
// If this status was updated recently (last interval), we return as-is.
if next := status.FetchedAt.Add(2 * time.Hour); time.Now().Before(next) {
// Default limit we allow
// statuses to be refreshed.
limit := 2 * time.Hour
if force {
// We specifically allow the force flag
// to force an early refresh (on a much
// smaller cooldown period).
limit = 5 * time.Minute
}
// If this status was updated recently (within limit), return as-is.
if next := status.FetchedAt.Add(limit); time.Now().Before(next) {
return true
}
@ -125,7 +136,7 @@ func (d *Dereferencer) getStatusByURI(ctx context.Context, requestUser string, u
}
// Check whether needs update.
if statusUpToDate(status) {
if statusUpToDate(status, false) {
// This is existing up-to-date status, ensure it is populated.
if err := d.state.DB.PopulateStatus(ctx, status); err != nil {
log.Errorf(ctx, "error populating existing status: %v", err)
@ -159,8 +170,8 @@ func (d *Dereferencer) RefreshStatus(
statusable ap.Statusable,
force bool,
) (*gtsmodel.Status, ap.Statusable, error) {
// Check whether needs update.
if !force && statusUpToDate(status) {
// Check whether status needs update.
if statusUpToDate(status, force) {
return status, nil, nil
}
@ -204,8 +215,8 @@ func (d *Dereferencer) RefreshStatusAsync(
statusable ap.Statusable,
force bool,
) {
// Check whether needs update.
if !force && statusUpToDate(status) {
// Check whether status needs update.
if statusUpToDate(status, force) {
return
}