summaryrefslogtreecommitdiff
path: root/internal/federation/dereferencing/status.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-12-15 14:24:39 +0000
committerLibravatar GitHub <noreply@github.com>2023-12-15 15:24:39 +0100
commitf4fcffc8b56ef73c184ae17892b69181961c15c7 (patch)
treeb678c44c9106e2ec8069dcf596a0554dee7410ab /internal/federation/dereferencing/status.go
parent[bugfix] Let templates deref pointers, as a treat (#2448) (diff)
downloadgotosocial-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/federation/dereferencing/status.go')
-rw-r--r--internal/federation/dereferencing/status.go27
1 files changed, 19 insertions, 8 deletions
diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go
index 8a8ec60b1..2a2b99d25 100644
--- a/internal/federation/dereferencing/status.go
+++ b/internal/federation/dereferencing/status.go
@@ -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
}