Refactor/tidy (#261)

* tidy up streaming

* cut down code duplication

* test get followers/following

* test streaming processor

* fix some test models

* add TimeMustParse

* fix uri / url typo

* make trace logging less verbose

* make logging more consistent

* disable quote on logging

* remove context.Background

* remove many extraneous mastodon references

* regenerate swagger

* don't log query on no rows result

* log latency first for easier reading
This commit is contained in:
tobi 2021-10-04 15:24:19 +02:00 committed by GitHub
commit e04b187702
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
126 changed files with 1192 additions and 955 deletions

View file

@ -5,12 +5,9 @@ import (
"fmt"
"net/url"
"github.com/go-fed/activity/streams"
"github.com/go-fed/activity/streams/vocab"
"github.com/sirupsen/logrus"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/util"
)
// Followers obtains the Followers Collection for an actor with the
@ -22,39 +19,28 @@ import (
func (f *federatingDB) Followers(ctx context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) {
l := f.log.WithFields(
logrus.Fields{
"func": "Followers",
"actorIRI": actorIRI.String(),
"func": "Followers",
"id": actorIRI,
},
)
l.Debugf("entering FOLLOWERS function with actorIRI %s", actorIRI.String())
l.Debug("entering Followers")
acct := &gtsmodel.Account{}
if util.IsUserPath(actorIRI) {
acct, err = f.db.GetAccountByURI(ctx, actorIRI.String())
if err != nil {
return nil, fmt.Errorf("FOLLOWERS: db error getting account with uri %s: %s", actorIRI.String(), err)
}
} else if util.IsFollowersPath(actorIRI) {
if err := f.db.GetWhere(ctx, []db.Where{{Key: "followers_uri", Value: actorIRI.String()}}, acct); err != nil {
return nil, fmt.Errorf("FOLLOWERS: db error getting account with followers uri %s: %s", actorIRI.String(), err)
}
} else {
return nil, fmt.Errorf("FOLLOWERS: could not parse actor IRI %s as users or followers path", actorIRI.String())
acct, err := f.getAccountForIRI(ctx, actorIRI)
if err != nil {
return nil, err
}
acctFollowers, err := f.db.GetAccountFollowedBy(ctx, acct.ID, false)
if err != nil {
return nil, fmt.Errorf("FOLLOWERS: db error getting followers for account id %s: %s", acct.ID, err)
return nil, fmt.Errorf("Followers: db error getting followers for account id %s: %s", acct.ID, err)
}
followers = streams.NewActivityStreamsCollection()
items := streams.NewActivityStreamsItemsProperty()
iris := []*url.URL{}
for _, follow := range acctFollowers {
if follow.Account == nil {
followAccount, err := f.db.GetAccountByID(ctx, follow.AccountID)
a, err := f.db.GetAccountByID(ctx, follow.AccountID)
if err != nil {
errWrapped := fmt.Errorf("FOLLOWERS: db error getting account id %s: %s", follow.AccountID, err)
errWrapped := fmt.Errorf("Followers: db error getting account id %s: %s", follow.AccountID, err)
if err == db.ErrNoEntries {
// no entry for this account id so it's probably been deleted and we haven't caught up yet
l.Error(errWrapped)
@ -64,15 +50,14 @@ func (f *federatingDB) Followers(ctx context.Context, actorIRI *url.URL) (follow
return nil, errWrapped
}
}
follow.Account = followAccount
follow.Account = a
}
uri, err := url.Parse(follow.Account.URI)
u, err := url.Parse(follow.Account.URI)
if err != nil {
return nil, fmt.Errorf("FOLLOWERS: error parsing %s as url: %s", follow.Account.URI, err)
return nil, err
}
items.AppendIRI(uri)
iris = append(iris, u)
}
followers.SetActivityStreamsItems(items)
return
return f.collectIRIs(ctx, iris)
}