From 7a1aa04bbbc9f95442c8850ef61d1d58bb12df74 Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Sun, 25 Sep 2022 12:09:41 +0100 Subject: [bugfix] update thread iterators to not use recursion (#851) * update thread iterators to not use recursion, rewrote both Signed-off-by: kim * fix endless descendant deref, don't error if fetching existing status Signed-off-by: kim * don't refetch remote ancestor statuses, improve descendant iter commenting Signed-off-by: kim * move collection page next logic so we capture first page of entities Signed-off-by: kim * improve log format argument quoting Signed-off-by: kim * improve code commenting of collection paging Signed-off-by: kim * only dereference announce's originating status if _not_ local. update DereferenceThread() signature. cleanup searchStatusByURI() Signed-off-by: kim Signed-off-by: kim --- internal/processing/search.go | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'internal/processing/search.go') diff --git a/internal/processing/search.go b/internal/processing/search.go index 3d7f3e56e..8bb2224a5 100644 --- a/internal/processing/search.go +++ b/internal/processing/search.go @@ -140,28 +140,36 @@ func (p *processor) SearchGet(ctx context.Context, authed *oauth.Auth, search *a } func (p *processor) searchStatusByURI(ctx context.Context, authed *oauth.Auth, uri *url.URL, resolve bool) (*gtsmodel.Status, error) { - l := log.WithFields(kv.Fields{ - {"uri", uri.String()}, - {"resolve", resolve}, - }...) + // Calculate URI string once + uriStr := uri.String() + + // Look for status locally (by URI), we only accept "not found" errors. + status, err := p.db.GetStatusByURI(ctx, uriStr) + if err != nil && !errors.Is(err, db.ErrNoEntries) { + return nil, fmt.Errorf("searchStatusByURI: error fetching status %q: %v", uriStr, err) + } else if err == nil { + return status, nil + } - if maybeStatus, err := p.db.GetStatusByURI(ctx, uri.String()); err == nil { - return maybeStatus, nil - } else if maybeStatus, err := p.db.GetStatusByURL(ctx, uri.String()); err == nil { - return maybeStatus, nil + // Again, look for status locally (by URL), we only accept "not found" errors. + status, err = p.db.GetStatusByURL(ctx, uriStr) + if err != nil && !errors.Is(err, db.ErrNoEntries) { + return nil, fmt.Errorf("searchStatusByURI: error fetching status %q: %v", uriStr, err) + } else if err == nil { + return status, nil } - // we don't have it locally so dereference it if we're allowed to if resolve { - status, _, err := p.federator.GetRemoteStatus(ctx, authed.Account.Username, uri, false, true) - if err == nil { - if err := p.federator.DereferenceRemoteThread(ctx, authed.Account.Username, uri); err != nil { - // try to deref the thread while we're here - l.Debugf("searchStatusByURI: error dereferencing remote thread: %s", err) - } - return status, nil + // This is a non-local status and we're allowed to resolve, so dereference it + status, statusable, err := p.federator.GetRemoteStatus(ctx, authed.Account.Username, uri, true, true) + if err != nil { + return nil, fmt.Errorf("searchStatusByURI: error fetching remote status %q: %v", uriStr, err) } + + // Attempt to dereference the status thread while we are here + p.federator.DereferenceRemoteThread(ctx, authed.Account.Username, uri, status, statusable) } + return nil, nil } -- cgit v1.2.3