mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-02 07:42:24 -06:00
[bugfix] Don't return Account or Status if new and dereferencing failed, other small fixes (#2563)
* tidy up account, status, webfingering logic a wee bit * go fmt * invert published check * alter resp initialization * get Published from account in typeutils * don't instantiate error for no darn good reason * shadow err * don't repeat error codes in wrapped errors * don't wrap error unnecessarily
This commit is contained in:
parent
07207e71e9
commit
e3052e8c82
13 changed files with 461 additions and 211 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue