diff options
Diffstat (limited to 'internal/federation/dereferencing/thread.go')
-rw-r--r-- | internal/federation/dereferencing/thread.go | 49 |
1 files changed, 21 insertions, 28 deletions
diff --git a/internal/federation/dereferencing/thread.go b/internal/federation/dereferencing/thread.go index cf6048689..b516f837b 100644 --- a/internal/federation/dereferencing/thread.go +++ b/internal/federation/dereferencing/thread.go @@ -35,34 +35,16 @@ import ( // ancesters we are willing to follow before returning error. const maxIter = 1000 -// DereferenceThread takes a statusable (something that has withReplies and withInReplyTo), -// and dereferences statusables in the conversation. -// -// This process involves working up and down the chain of replies, and parsing through the collections of IDs -// presented by remote instances as part of their replies collections, and will likely involve making several calls to -// multiple different hosts. -// -// This does not return error, as for robustness we do not want to error-out on a status because another further up / down has issues. -func (d *deref) DereferenceThread(ctx context.Context, username string, statusIRI *url.URL, status *gtsmodel.Status, statusable ap.Statusable) { - l := log.WithContext(ctx). - WithFields(kv.Fields{ - {"username", username}, - {"statusIRI", status.URI}, - }...) - - // Log function start - l.Trace("beginning") - +// dereferenceThread will dereference statuses both above and below the given status in a thread, it returns no error and is intended to be called asychronously. +func (d *deref) dereferenceThread(ctx context.Context, username string, statusIRI *url.URL, status *gtsmodel.Status, statusable ap.Statusable) { // Ensure that ancestors have been fully dereferenced if err := d.dereferenceStatusAncestors(ctx, username, status); err != nil { - l.Errorf("error dereferencing status ancestors: %v", err) - // we don't return error, we have deref'd as much as we can + log.Errorf(ctx, "error dereferencing status ancestors: %v", err) } // Ensure that descendants have been fully dereferenced if err := d.dereferenceStatusDescendants(ctx, username, statusIRI, statusable); err != nil { - l.Errorf("error dereferencing status descendants: %v", err) - // we don't return error, we have deref'd as much as we can + log.Errorf(ctx, "error dereferencing status descendants: %v", err) } } @@ -103,7 +85,7 @@ func (d *deref) dereferenceStatusAncestors(ctx context.Context, username string, } // Fetch this status from the database - localStatus, err := d.db.GetStatusByID(ctx, id) + localStatus, err := d.state.DB.GetStatusByID(ctx, id) if err != nil { return fmt.Errorf("error fetching local status %q: %w", id, err) } @@ -115,7 +97,10 @@ func (d *deref) dereferenceStatusAncestors(ctx context.Context, username string, l.Tracef("following remote status ancestors: %s", status.InReplyToURI) // Fetch the remote status found at this IRI - remoteStatus, _, err := d.GetStatus(ctx, username, replyIRI, false, false) + remoteStatus, _, err := d.getStatusByURI(ctx, + username, + replyIRI, + ) if err != nil { return fmt.Errorf("error fetching remote status %q: %w", status.InReplyToURI, err) } @@ -277,10 +262,15 @@ stackLoop: continue itemLoop } - // Dereference the remote status and store in the database - _, statusable, err := d.GetStatus(ctx, username, itemIRI, true, false) + // Dereference the remote status and store in the database. + _, statusable, err := d.getStatusByURI(ctx, username, itemIRI) if err != nil { - l.Errorf("error dereferencing remote status %q: %s", itemIRI.String(), err) + l.Errorf("error dereferencing remote status %s: %v", itemIRI, err) + continue itemLoop + } + + if statusable == nil { + // Already up-to-date. continue itemLoop } @@ -307,7 +297,10 @@ stackLoop: } // Dereference this next collection page by its IRI - collectionPage, err := d.DereferenceCollectionPage(ctx, username, pageNextIRI) + collectionPage, err := d.dereferenceCollectionPage(ctx, + username, + pageNextIRI, + ) if err != nil { l.Errorf("error dereferencing remote collection page %q: %s", pageNextIRI.String(), err) continue stackLoop |