diff options
author | 2022-09-25 12:09:41 +0100 | |
---|---|---|
committer | 2022-09-25 13:09:41 +0200 | |
commit | 7a1aa04bbbc9f95442c8850ef61d1d58bb12df74 (patch) | |
tree | 7b05a52914deb1f838539a3196edca287942fd95 /internal/processing/search.go | |
parent | [bugfix] Wrap media reader in length reader to determine length if no `conten... (diff) | |
download | gotosocial-7a1aa04bbbc9f95442c8850ef61d1d58bb12df74.tar.xz |
[bugfix] update thread iterators to not use recursion (#851)
* update thread iterators to not use recursion, rewrote both
Signed-off-by: kim <grufwub@gmail.com>
* fix endless descendant deref, don't error if fetching existing status
Signed-off-by: kim <grufwub@gmail.com>
* don't refetch remote ancestor statuses, improve descendant iter commenting
Signed-off-by: kim <grufwub@gmail.com>
* move collection page next logic so we capture first page of entities
Signed-off-by: kim <grufwub@gmail.com>
* improve log format argument quoting
Signed-off-by: kim <grufwub@gmail.com>
* improve code commenting of collection paging
Signed-off-by: kim <grufwub@gmail.com>
* only dereference announce's originating status if _not_ local. update DereferenceThread() signature. cleanup searchStatusByURI()
Signed-off-by: kim <grufwub@gmail.com>
Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/processing/search.go')
-rw-r--r-- | internal/processing/search.go | 40 |
1 files changed, 24 insertions, 16 deletions
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 } |