diff options
author | 2023-05-31 09:39:54 +0100 | |
---|---|---|
committer | 2023-05-31 10:39:54 +0200 | |
commit | 9da20eeecb60a88688d17cecb4bfc78c4241558e (patch) | |
tree | afcdf5008fc51c3ed620ae1a9dca0e10d14542ae /internal/federation/dereferencing/status.go | |
parent | [docs] clarify other federation modes not yet implemented (#1849) (diff) | |
download | gotosocial-9da20eeecb60a88688d17cecb4bfc78c4241558e.tar.xz |
[bugfix] only attempt to populate account/statuses from DB if already exist (#1839)
* only attempt to populate account/statuses from DB if already up-to-date
Signed-off-by: kim <grufwub@gmail.com>
* add missing status is-up-to-date check :grimace: + ensure populated if so
Signed-off-by: kim <grufwub@gmail.com>
---------
Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/federation/dereferencing/status.go')
-rw-r--r-- | internal/federation/dereferencing/status.go | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/internal/federation/dereferencing/status.go b/internal/federation/dereferencing/status.go index fede8b3ea..e4ecee639 100644 --- a/internal/federation/dereferencing/status.go +++ b/internal/federation/dereferencing/status.go @@ -27,6 +27,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/ap" "github.com/superseriousbusiness/gotosocial/internal/config" "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/id" @@ -80,15 +81,23 @@ func (d *deref) getStatusByURI(ctx context.Context, requestUser string, uri *url err error ) - // Search the database for existing status with ID URI. - status, err = d.state.DB.GetStatusByURI(ctx, uriStr) + // Search the database for existing status with URI. + status, err = d.state.DB.GetStatusByURI( + // request a barebones object, it may be in the + // db but with related models not yet dereferenced. + gtscontext.SetBarebones(ctx), + uriStr, + ) if err != nil && !errors.Is(err, db.ErrNoEntries) { return nil, nil, gtserror.Newf("error checking database for status %s by uri: %w", uriStr, err) } if status == nil { - // Else, search the database for existing by ID URL. - status, err = d.state.DB.GetStatusByURL(ctx, uriStr) + // Else, search the database for existing by URL. + status, err = d.state.DB.GetStatusByURL( + gtscontext.SetBarebones(ctx), + uriStr, + ) if err != nil && !errors.Is(err, db.ErrNoEntries) { return nil, nil, gtserror.Newf("error checking database for status %s by url: %w", uriStr, err) } @@ -107,6 +116,15 @@ func (d *deref) getStatusByURI(ctx context.Context, requestUser string, uri *url }, nil) } + // Check whether needs update. + if statusUpToDate(status) { + // 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) + } + return status, nil, nil + } + // Try to update + deref existing status model. latest, apubStatus, err := d.enrichStatus(ctx, requestUser, |