diff options
Diffstat (limited to 'internal/federation/dereferencing/status.go')
-rw-r--r-- | internal/federation/dereferencing/status.go | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go index 1eb7d6fdb..7dc22a354 100644 --- a/internal/federation/dereferencing/status.go +++ b/internal/federation/dereferencing/status.go @@ -294,10 +294,30 @@ func (d *Dereferencer) enrichStatusSafely( apubStatus, ) - if gtserror.StatusCode(err) >= 400 { - // Update fetch-at to slow re-attempts. + if code := gtserror.StatusCode(err); code >= 400 { + // No matter what, log the error + // so instance admins have an idea + // why something isn't working. + log.Info(ctx, err) + + if isNew { + // This was a new status enrich + // attempt which failed before we + // got to store it, so we can't + // return anything useful. + return nil, nil, isNew, err + } + + // We had this status stored already + // before this enrichment attempt. + // + // Update fetched_at to slow re-attempts + // but don't return early. We can still + // return the model we had stored already. status.FetchedAt = time.Now() - _ = d.state.DB.UpdateStatus(ctx, status, "fetched_at") + if err := d.state.DB.UpdateStatus(ctx, status, "fetched_at"); err != nil { + log.Errorf(ctx, "error updating status fetched_at: %v", err) + } } // Unlock now @@ -358,7 +378,7 @@ func (d *Dereferencer) enrichStatus( // Dereference latest version of the status. b, err := tsport.Dereference(ctx, uri) if err != nil { - err := gtserror.Newf("error deferencing %s: %w", uri, err) + err := gtserror.Newf("error dereferencing %s: %w", uri, err) return nil, nil, gtserror.SetUnretrievable(err) } @@ -388,16 +408,21 @@ func (d *Dereferencer) enrichStatus( return nil, nil, gtserror.Newf("error converting statusable to gts model for status %s: %w", uri, err) } - // Use existing status ID. - latestStatus.ID = status.ID - if latestStatus.ID == "" { - - // Generate new status ID from the provided creation date. + // Check if we've previously + // stored this status in the DB. + // If we have, it'll be ID'd. + var isNew = (status.ID == "") + if isNew { + // No ID, we haven't stored this status before. + // Generate new status ID from the status publication time. latestStatus.ID, err = id.NewULIDFromTime(latestStatus.CreatedAt) if err != nil { log.Errorf(ctx, "invalid created at date (falling back to 'now'): %v", err) latestStatus.ID = id.NewULID() // just use "now" } + } else { + // Reuse existing status ID. + latestStatus.ID = status.ID } // Carry-over values and set fetch time. @@ -436,10 +461,7 @@ func (d *Dereferencer) enrichStatus( return nil, nil, gtserror.Newf("error populating emojis for status %s: %w", uri, err) } - if status.CreatedAt.IsZero() { - // CreatedAt will be zero if no local copy was - // found in one of the GetStatusBy___() functions. - // + if isNew { // This is new, put the status in the database. err := d.state.DB.PutStatus(ctx, latestStatus) if err != nil { |