mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[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>
This commit is contained in:
@ -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()
|
||||
|
||||
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
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user