mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-09 20:28:06 -06:00
Pg to bun (#148)
* start moving to bun * changing more stuff * more * and yet more * tests passing * seems stable now * more big changes * small fix * little fixes
This commit is contained in:
parent
071eca20ce
commit
2dc9fc1626
713 changed files with 98694 additions and 22704 deletions
|
|
@ -86,7 +86,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
|
|||
if util.IsFollowPath(acceptedObjectIRI) {
|
||||
// ACCEPT FOLLOW
|
||||
gtsFollowRequest := >smodel.FollowRequest{}
|
||||
if err := f.db.GetWhere([]db.Where{{Key: "uri", Value: acceptedObjectIRI.String()}}, gtsFollowRequest); err != nil {
|
||||
if err := f.db.GetWhere(ctx, []db.Where{{Key: "uri", Value: acceptedObjectIRI.String()}}, gtsFollowRequest); err != nil {
|
||||
return fmt.Errorf("ACCEPT: couldn't get follow request with id %s from the database: %s", acceptedObjectIRI.String(), err)
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
|
|||
if gtsFollowRequest.AccountID != targetAcct.ID {
|
||||
return errors.New("ACCEPT: follow object account and inbox account were not the same")
|
||||
}
|
||||
follow, err := f.db.AcceptFollowRequest(gtsFollowRequest.AccountID, gtsFollowRequest.TargetAccountID)
|
||||
follow, err := f.db.AcceptFollowRequest(ctx, gtsFollowRequest.AccountID, gtsFollowRequest.TargetAccountID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -123,7 +123,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
|
|||
return errors.New("ACCEPT: couldn't parse follow into vocab.ActivityStreamsFollow")
|
||||
}
|
||||
// convert the follow to something we can understand
|
||||
gtsFollow, err := f.typeConverter.ASFollowToFollow(asFollow)
|
||||
gtsFollow, err := f.typeConverter.ASFollowToFollow(ctx, asFollow)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ACCEPT: error converting asfollow to gtsfollow: %s", err)
|
||||
}
|
||||
|
|
@ -131,7 +131,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
|
|||
if gtsFollow.AccountID != targetAcct.ID {
|
||||
return errors.New("ACCEPT: follow object account and inbox account were not the same")
|
||||
}
|
||||
follow, err := f.db.AcceptFollowRequest(gtsFollow.AccountID, gtsFollow.TargetAccountID)
|
||||
follow, err := f.db.AcceptFollowRequest(ctx, gtsFollow.AccountID, gtsFollow.TargetAccountID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ func (f *federatingDB) Announce(ctx context.Context, announce vocab.ActivityStre
|
|||
return nil
|
||||
}
|
||||
|
||||
boost, isNew, err := f.typeConverter.ASAnnounceToStatus(announce)
|
||||
boost, isNew, err := f.typeConverter.ASAnnounceToStatus(ctx, announce)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ANNOUNCE: error converting announce to boost: %s", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
|
|||
case gtsmodel.ActivityStreamsNote:
|
||||
// CREATE A NOTE
|
||||
note := objectIter.GetActivityStreamsNote()
|
||||
status, err := f.typeConverter.ASStatusToStatus(note)
|
||||
status, err := f.typeConverter.ASStatusToStatus(ctx, note)
|
||||
if err != nil {
|
||||
return fmt.Errorf("CREATE: error converting note to status: %s", err)
|
||||
}
|
||||
|
|
@ -112,7 +112,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
|
|||
}
|
||||
status.ID = statusID
|
||||
|
||||
if err := f.db.PutStatus(status); err != nil {
|
||||
if err := f.db.PutStatus(ctx, status); err != nil {
|
||||
if err == db.ErrAlreadyExists {
|
||||
// the status already exists in the database, which means we've already handled everything else,
|
||||
// so we can just return nil here and be done with it.
|
||||
|
|
@ -137,7 +137,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
|
|||
return errors.New("CREATE: could not convert type to follow")
|
||||
}
|
||||
|
||||
followRequest, err := f.typeConverter.ASFollowToFollowRequest(follow)
|
||||
followRequest, err := f.typeConverter.ASFollowToFollowRequest(ctx, follow)
|
||||
if err != nil {
|
||||
return fmt.Errorf("CREATE: could not convert Follow to follow request: %s", err)
|
||||
}
|
||||
|
|
@ -148,7 +148,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
|
|||
}
|
||||
followRequest.ID = newID
|
||||
|
||||
if err := f.db.Put(followRequest); err != nil {
|
||||
if err := f.db.Put(ctx, followRequest); err != nil {
|
||||
return fmt.Errorf("CREATE: database error inserting follow request: %s", err)
|
||||
}
|
||||
|
||||
|
|
@ -165,7 +165,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
|
|||
return errors.New("CREATE: could not convert type to like")
|
||||
}
|
||||
|
||||
fave, err := f.typeConverter.ASLikeToFave(like)
|
||||
fave, err := f.typeConverter.ASLikeToFave(ctx, like)
|
||||
if err != nil {
|
||||
return fmt.Errorf("CREATE: could not convert Like to fave: %s", err)
|
||||
}
|
||||
|
|
@ -176,7 +176,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
|
|||
}
|
||||
fave.ID = newID
|
||||
|
||||
if err := f.db.Put(fave); err != nil {
|
||||
if err := f.db.Put(ctx, fave); err != nil {
|
||||
return fmt.Errorf("CREATE: database error inserting fave: %s", err)
|
||||
}
|
||||
|
||||
|
|
@ -193,7 +193,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
|
|||
return errors.New("CREATE: could not convert type to block")
|
||||
}
|
||||
|
||||
block, err := f.typeConverter.ASBlockToBlock(blockable)
|
||||
block, err := f.typeConverter.ASBlockToBlock(ctx, blockable)
|
||||
if err != nil {
|
||||
return fmt.Errorf("CREATE: could not convert Block to gts model block")
|
||||
}
|
||||
|
|
@ -204,7 +204,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
|
|||
}
|
||||
block.ID = newID
|
||||
|
||||
if err := f.db.Put(block); err != nil {
|
||||
if err := f.db.Put(ctx, block); err != nil {
|
||||
return fmt.Errorf("CREATE: database error inserting block: %s", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,11 +69,11 @@ func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error {
|
|||
|
||||
// in a delete we only get the URI, we can't know if we have a status or a profile or something else,
|
||||
// so we have to try a few different things...
|
||||
s, err := f.db.GetStatusByURI(id.String())
|
||||
s, err := f.db.GetStatusByURI(ctx, id.String())
|
||||
if err == nil {
|
||||
// it's a status
|
||||
l.Debugf("uri is for status with id: %s", s.ID)
|
||||
if err := f.db.DeleteByID(s.ID, >smodel.Status{}); err != nil {
|
||||
if err := f.db.DeleteByID(ctx, s.ID, >smodel.Status{}); err != nil {
|
||||
return fmt.Errorf("DELETE: err deleting status: %s", err)
|
||||
}
|
||||
fromFederatorChan <- gtsmodel.FromFederator{
|
||||
|
|
@ -84,11 +84,11 @@ func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error {
|
|||
}
|
||||
}
|
||||
|
||||
a, err := f.db.GetAccountByURI(id.String())
|
||||
a, err := f.db.GetAccountByURI(ctx, id.String())
|
||||
if err == nil {
|
||||
// it's an account
|
||||
l.Debugf("uri is for an account with id: %s", s.ID)
|
||||
if err := f.db.DeleteByID(a.ID, >smodel.Account{}); err != nil {
|
||||
l.Debugf("uri is for an account with id: %s", a.ID)
|
||||
if err := f.db.DeleteByID(ctx, a.ID, >smodel.Account{}); err != nil {
|
||||
return fmt.Errorf("DELETE: err deleting account: %s", err)
|
||||
}
|
||||
fromFederatorChan <- gtsmodel.FromFederator{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import (
|
|||
// If modified, the library will then call Update.
|
||||
//
|
||||
// The library makes this call only after acquiring a lock first.
|
||||
func (f *federatingDB) Followers(c context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) {
|
||||
func (f *federatingDB) Followers(ctx context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) {
|
||||
l := f.log.WithFields(
|
||||
logrus.Fields{
|
||||
"func": "Followers",
|
||||
|
|
@ -31,19 +31,19 @@ func (f *federatingDB) Followers(c context.Context, actorIRI *url.URL) (follower
|
|||
acct := >smodel.Account{}
|
||||
|
||||
if util.IsUserPath(actorIRI) {
|
||||
acct, err = f.db.GetAccountByURI(actorIRI.String())
|
||||
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([]db.Where{{Key: "followers_uri", Value: actorIRI.String()}}, acct); err != nil {
|
||||
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())
|
||||
}
|
||||
|
||||
acctFollowers, err := f.db.GetAccountFollowedBy(acct.ID, false)
|
||||
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)
|
||||
}
|
||||
|
|
@ -51,13 +51,17 @@ func (f *federatingDB) Followers(c context.Context, actorIRI *url.URL) (follower
|
|||
followers = streams.NewActivityStreamsCollection()
|
||||
items := streams.NewActivityStreamsItemsProperty()
|
||||
for _, follow := range acctFollowers {
|
||||
gtsFollower := >smodel.Account{}
|
||||
if err := f.db.GetByID(follow.AccountID, gtsFollower); err != nil {
|
||||
return nil, fmt.Errorf("FOLLOWERS: db error getting account id %s: %s", follow.AccountID, err)
|
||||
if follow.Account == nil {
|
||||
followAccount, err := f.db.GetAccountByID(ctx, follow.AccountID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("FOLLOWERS: db error getting account id %s: %s", follow.AccountID, err)
|
||||
}
|
||||
follow.Account = followAccount
|
||||
}
|
||||
uri, err := url.Parse(gtsFollower.URI)
|
||||
|
||||
uri, err := url.Parse(follow.Account.URI)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("FOLLOWERS: error parsing %s as url: %s", gtsFollower.URI, err)
|
||||
return nil, fmt.Errorf("FOLLOWERS: error parsing %s as url: %s", follow.Account.URI, err)
|
||||
}
|
||||
items.AppendIRI(uri)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import (
|
|||
// If modified, the library will then call Update.
|
||||
//
|
||||
// The library makes this call only after acquiring a lock first.
|
||||
func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (following vocab.ActivityStreamsCollection, err error) {
|
||||
func (f *federatingDB) Following(ctx context.Context, actorIRI *url.URL) (following vocab.ActivityStreamsCollection, err error) {
|
||||
l := f.log.WithFields(
|
||||
logrus.Fields{
|
||||
"func": "Following",
|
||||
|
|
@ -34,7 +34,7 @@ func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (followin
|
|||
return nil, fmt.Errorf("FOLLOWING: error parsing user path: %s", err)
|
||||
}
|
||||
|
||||
a, err := f.db.GetLocalAccountByUsername(username)
|
||||
a, err := f.db.GetLocalAccountByUsername(ctx, username)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("FOLLOWING: db error getting account with uri %s: %s", actorIRI.String(), err)
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (followin
|
|||
return nil, fmt.Errorf("FOLLOWING: error parsing following path: %s", err)
|
||||
}
|
||||
|
||||
a, err := f.db.GetLocalAccountByUsername(username)
|
||||
a, err := f.db.GetLocalAccountByUsername(ctx, username)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("FOLLOWING: db error getting account with following uri %s: %s", actorIRI.String(), err)
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (followin
|
|||
return nil, fmt.Errorf("FOLLOWING: could not parse actor IRI %s as users or following path", actorIRI.String())
|
||||
}
|
||||
|
||||
acctFollowing, err := f.db.GetAccountFollows(acct.ID)
|
||||
acctFollowing, err := f.db.GetAccountFollows(ctx, acct.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("FOLLOWING: db error getting following for account id %s: %s", acct.ID, err)
|
||||
}
|
||||
|
|
@ -64,13 +64,17 @@ func (f *federatingDB) Following(c context.Context, actorIRI *url.URL) (followin
|
|||
following = streams.NewActivityStreamsCollection()
|
||||
items := streams.NewActivityStreamsItemsProperty()
|
||||
for _, follow := range acctFollowing {
|
||||
gtsFollowing := >smodel.Account{}
|
||||
if err := f.db.GetByID(follow.AccountID, gtsFollowing); err != nil {
|
||||
return nil, fmt.Errorf("FOLLOWING: db error getting account id %s: %s", follow.AccountID, err)
|
||||
if follow.Account == nil {
|
||||
followAccount, err := f.db.GetAccountByID(ctx, follow.AccountID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("FOLLOWING: db error getting account id %s: %s", follow.AccountID, err)
|
||||
}
|
||||
follow.Account = followAccount
|
||||
}
|
||||
uri, err := url.Parse(gtsFollowing.URI)
|
||||
|
||||
uri, err := url.Parse(follow.Account.URI)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("FOLLOWING: error parsing %s as url: %s", gtsFollowing.URI, err)
|
||||
return nil, fmt.Errorf("FOLLOWING: error parsing %s as url: %s", follow.Account.URI, err)
|
||||
}
|
||||
items.AppendIRI(uri)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import (
|
|||
// Get returns the database entry for the specified id.
|
||||
//
|
||||
// The library makes this call only after acquiring a lock first.
|
||||
func (f *federatingDB) Get(c context.Context, id *url.URL) (value vocab.Type, err error) {
|
||||
func (f *federatingDB) Get(ctx context.Context, id *url.URL) (value vocab.Type, err error) {
|
||||
l := f.log.WithFields(
|
||||
logrus.Fields{
|
||||
"func": "Get",
|
||||
|
|
@ -43,17 +43,17 @@ func (f *federatingDB) Get(c context.Context, id *url.URL) (value vocab.Type, er
|
|||
l.Debug("entering GET function")
|
||||
|
||||
if util.IsUserPath(id) {
|
||||
acct, err := f.db.GetAccountByURI(id.String())
|
||||
acct, err := f.db.GetAccountByURI(ctx, id.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l.Debug("is user path! returning account")
|
||||
return f.typeConverter.AccountToAS(acct)
|
||||
return f.typeConverter.AccountToAS(ctx, acct)
|
||||
}
|
||||
|
||||
if util.IsFollowersPath(id) {
|
||||
acct := >smodel.Account{}
|
||||
if err := f.db.GetWhere([]db.Where{{Key: "followers_uri", Value: id.String()}}, acct); err != nil {
|
||||
if err := f.db.GetWhere(ctx, []db.Where{{Key: "followers_uri", Value: id.String()}}, acct); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -62,12 +62,12 @@ func (f *federatingDB) Get(c context.Context, id *url.URL) (value vocab.Type, er
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return f.Followers(c, followersURI)
|
||||
return f.Followers(ctx, followersURI)
|
||||
}
|
||||
|
||||
if util.IsFollowingPath(id) {
|
||||
acct := >smodel.Account{}
|
||||
if err := f.db.GetWhere([]db.Where{{Key: "following_uri", Value: id.String()}}, acct); err != nil {
|
||||
if err := f.db.GetWhere(ctx, []db.Where{{Key: "following_uri", Value: id.String()}}, acct); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ func (f *federatingDB) Get(c context.Context, id *url.URL) (value vocab.Type, er
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return f.Following(c, followingURI)
|
||||
return f.Following(ctx, followingURI)
|
||||
}
|
||||
|
||||
return nil, errors.New("could not get")
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import (
|
|||
// at the specified IRI, for prepending new items.
|
||||
//
|
||||
// The library makes this call only after acquiring a lock first.
|
||||
func (f *federatingDB) GetOutbox(c context.Context, outboxIRI *url.URL) (inbox vocab.ActivityStreamsOrderedCollectionPage, err error) {
|
||||
func (f *federatingDB) GetOutbox(ctx context.Context, outboxIRI *url.URL) (inbox vocab.ActivityStreamsOrderedCollectionPage, err error) {
|
||||
l := f.log.WithFields(
|
||||
logrus.Fields{
|
||||
"func": "GetOutbox",
|
||||
|
|
@ -51,7 +51,7 @@ func (f *federatingDB) GetOutbox(c context.Context, outboxIRI *url.URL) (inbox v
|
|||
// database entries. Separate calls to Create will do that.
|
||||
//
|
||||
// The library makes this call only after acquiring a lock first.
|
||||
func (f *federatingDB) SetOutbox(c context.Context, outbox vocab.ActivityStreamsOrderedCollectionPage) error {
|
||||
func (f *federatingDB) SetOutbox(ctx context.Context, outbox vocab.ActivityStreamsOrderedCollectionPage) error {
|
||||
l := f.log.WithFields(
|
||||
logrus.Fields{
|
||||
"func": "SetOutbox",
|
||||
|
|
@ -66,7 +66,7 @@ func (f *federatingDB) SetOutbox(c context.Context, outbox vocab.ActivityStreams
|
|||
// actor's inbox IRI.
|
||||
//
|
||||
// The library makes this call only after acquiring a lock first.
|
||||
func (f *federatingDB) OutboxForInbox(c context.Context, inboxIRI *url.URL) (outboxIRI *url.URL, err error) {
|
||||
func (f *federatingDB) OutboxForInbox(ctx context.Context, inboxIRI *url.URL) (outboxIRI *url.URL, err error) {
|
||||
l := f.log.WithFields(
|
||||
logrus.Fields{
|
||||
"func": "OutboxForInbox",
|
||||
|
|
@ -79,7 +79,7 @@ func (f *federatingDB) OutboxForInbox(c context.Context, inboxIRI *url.URL) (out
|
|||
return nil, fmt.Errorf("%s is not an inbox URI", inboxIRI.String())
|
||||
}
|
||||
acct := >smodel.Account{}
|
||||
if err := f.db.GetWhere([]db.Where{{Key: "inbox_uri", Value: inboxIRI.String()}}, acct); err != nil {
|
||||
if err := f.db.GetWhere(ctx, []db.Where{{Key: "inbox_uri", Value: inboxIRI.String()}}, acct); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
return nil, fmt.Errorf("no actor found that corresponds to inbox %s", inboxIRI.String())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import (
|
|||
// Owns returns true if the IRI belongs to this instance, and if
|
||||
// the database has an entry for the IRI.
|
||||
// The library makes this call only after acquiring a lock first.
|
||||
func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
|
||||
func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {
|
||||
l := f.log.WithFields(
|
||||
logrus.Fields{
|
||||
"func": "Owns",
|
||||
|
|
@ -54,7 +54,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
|
|||
if err != nil {
|
||||
return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)
|
||||
}
|
||||
status, err := f.db.GetStatusByURI(uid)
|
||||
status, err := f.db.GetStatusByURI(ctx, uid)
|
||||
if err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
// there are no entries for this status
|
||||
|
|
@ -71,7 +71,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
|
|||
if err != nil {
|
||||
return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)
|
||||
}
|
||||
if _, err := f.db.GetLocalAccountByUsername(username); err != nil {
|
||||
if _, err := f.db.GetLocalAccountByUsername(ctx, username); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
// there are no entries for this username
|
||||
return false, nil
|
||||
|
|
@ -88,7 +88,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
|
|||
if err != nil {
|
||||
return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)
|
||||
}
|
||||
if _, err := f.db.GetLocalAccountByUsername(username); err != nil {
|
||||
if _, err := f.db.GetLocalAccountByUsername(ctx, username); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
// there are no entries for this username
|
||||
return false, nil
|
||||
|
|
@ -105,7 +105,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
|
|||
if err != nil {
|
||||
return false, fmt.Errorf("error parsing statuses path for url %s: %s", id.String(), err)
|
||||
}
|
||||
if _, err := f.db.GetLocalAccountByUsername(username); err != nil {
|
||||
if _, err := f.db.GetLocalAccountByUsername(ctx, username); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
// there are no entries for this username
|
||||
return false, nil
|
||||
|
|
@ -122,7 +122,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
|
|||
if err != nil {
|
||||
return false, fmt.Errorf("error parsing like path for url %s: %s", id.String(), err)
|
||||
}
|
||||
if _, err := f.db.GetLocalAccountByUsername(username); err != nil {
|
||||
if _, err := f.db.GetLocalAccountByUsername(ctx, username); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
// there are no entries for this username
|
||||
return false, nil
|
||||
|
|
@ -130,7 +130,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
|
|||
// an actual error happened
|
||||
return false, fmt.Errorf("database error fetching account with username %s: %s", username, err)
|
||||
}
|
||||
if err := f.db.GetByID(likeID, >smodel.StatusFave{}); err != nil {
|
||||
if err := f.db.GetByID(ctx, likeID, >smodel.StatusFave{}); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
// there are no entries
|
||||
return false, nil
|
||||
|
|
@ -147,7 +147,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
|
|||
if err != nil {
|
||||
return false, fmt.Errorf("error parsing block path for url %s: %s", id.String(), err)
|
||||
}
|
||||
if _, err := f.db.GetLocalAccountByUsername(username); err != nil {
|
||||
if _, err := f.db.GetLocalAccountByUsername(ctx, username); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
// there are no entries for this username
|
||||
return false, nil
|
||||
|
|
@ -155,7 +155,7 @@ func (f *federatingDB) Owns(c context.Context, id *url.URL) (bool, error) {
|
|||
// an actual error happened
|
||||
return false, fmt.Errorf("database error fetching account with username %s: %s", username, err)
|
||||
}
|
||||
if err := f.db.GetByID(blockID, >smodel.Block{}); err != nil {
|
||||
if err := f.db.GetByID(ctx, blockID, >smodel.Block{}); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
// there are no entries
|
||||
return false, nil
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
|
|||
return errors.New("UNDO: follow actor and activity actor not the same")
|
||||
}
|
||||
// convert the follow to something we can understand
|
||||
gtsFollow, err := f.typeConverter.ASFollowToFollow(ASFollow)
|
||||
gtsFollow, err := f.typeConverter.ASFollowToFollow(ctx, ASFollow)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UNDO: error converting asfollow to gtsfollow: %s", err)
|
||||
}
|
||||
|
|
@ -92,11 +92,11 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
|
|||
return errors.New("UNDO: follow object account and inbox account were not the same")
|
||||
}
|
||||
// delete any existing FOLLOW
|
||||
if err := f.db.DeleteWhere([]db.Where{{Key: "uri", Value: gtsFollow.URI}}, >smodel.Follow{}); err != nil {
|
||||
if err := f.db.DeleteWhere(ctx, []db.Where{{Key: "uri", Value: gtsFollow.URI}}, >smodel.Follow{}); err != nil {
|
||||
return fmt.Errorf("UNDO: db error removing follow: %s", err)
|
||||
}
|
||||
// delete any existing FOLLOW REQUEST
|
||||
if err := f.db.DeleteWhere([]db.Where{{Key: "uri", Value: gtsFollow.URI}}, >smodel.FollowRequest{}); err != nil {
|
||||
if err := f.db.DeleteWhere(ctx, []db.Where{{Key: "uri", Value: gtsFollow.URI}}, >smodel.FollowRequest{}); err != nil {
|
||||
return fmt.Errorf("UNDO: db error removing follow request: %s", err)
|
||||
}
|
||||
l.Debug("follow undone")
|
||||
|
|
@ -116,7 +116,7 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
|
|||
return errors.New("UNDO: block actor and activity actor not the same")
|
||||
}
|
||||
// convert the block to something we can understand
|
||||
gtsBlock, err := f.typeConverter.ASBlockToBlock(ASBlock)
|
||||
gtsBlock, err := f.typeConverter.ASBlockToBlock(ctx, ASBlock)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UNDO: error converting asblock to gtsblock: %s", err)
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
|
|||
return errors.New("UNDO: block object account and inbox account were not the same")
|
||||
}
|
||||
// delete any existing BLOCK
|
||||
if err := f.db.DeleteWhere([]db.Where{{Key: "uri", Value: gtsBlock.URI}}, >smodel.Block{}); err != nil {
|
||||
if err := f.db.DeleteWhere(ctx, []db.Where{{Key: "uri", Value: gtsBlock.URI}}, >smodel.Block{}); err != nil {
|
||||
return fmt.Errorf("UNDO: db error removing block: %s", err)
|
||||
}
|
||||
l.Debug("block undone")
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error {
|
|||
accountable = i
|
||||
}
|
||||
|
||||
updatedAcct, err := f.typeConverter.ASRepresentationToAccount(accountable, true)
|
||||
updatedAcct, err := f.typeConverter.ASRepresentationToAccount(ctx, accountable, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UPDATE: error converting to account: %s", err)
|
||||
}
|
||||
|
|
@ -152,7 +152,8 @@ func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error {
|
|||
}
|
||||
|
||||
updatedAcct.ID = requestingAcct.ID // set this here so the db will update properly instead of trying to PUT this and getting constraint issues
|
||||
if err := f.db.UpdateByID(requestingAcct.ID, updatedAcct); err != nil {
|
||||
updatedAcct, err = f.db.UpdateAccount(ctx, updatedAcct)
|
||||
if err != nil {
|
||||
return fmt.Errorf("UPDATE: database error inserting updated account: %s", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ func sameActor(activityActor vocab.ActivityStreamsActorProperty, followActor voc
|
|||
//
|
||||
// The go-fed library will handle setting the 'id' property on the
|
||||
// activity or object provided with the value returned.
|
||||
func (f *federatingDB) NewID(c context.Context, t vocab.Type) (idURL *url.URL, err error) {
|
||||
func (f *federatingDB) NewID(ctx context.Context, t vocab.Type) (idURL *url.URL, err error) {
|
||||
l := f.log.WithFields(
|
||||
logrus.Fields{
|
||||
"func": "NewID",
|
||||
|
|
@ -98,7 +98,7 @@ func (f *federatingDB) NewID(c context.Context, t vocab.Type) (idURL *url.URL, e
|
|||
// take the IRI of the first actor we can find (there should only be one)
|
||||
if iter.IsIRI() {
|
||||
// if there's an error here, just use the fallback behavior -- we don't need to return an error here
|
||||
if actorAccount, err := f.db.GetAccountByURI(iter.GetIRI().String()); err == nil {
|
||||
if actorAccount, err := f.db.GetAccountByURI(ctx, iter.GetIRI().String()); err == nil {
|
||||
newID, err := id.NewRandomULID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -199,7 +199,7 @@ func (f *federatingDB) NewID(c context.Context, t vocab.Type) (idURL *url.URL, e
|
|||
// ActorForOutbox fetches the actor's IRI for the given outbox IRI.
|
||||
//
|
||||
// The library makes this call only after acquiring a lock first.
|
||||
func (f *federatingDB) ActorForOutbox(c context.Context, outboxIRI *url.URL) (actorIRI *url.URL, err error) {
|
||||
func (f *federatingDB) ActorForOutbox(ctx context.Context, outboxIRI *url.URL) (actorIRI *url.URL, err error) {
|
||||
l := f.log.WithFields(
|
||||
logrus.Fields{
|
||||
"func": "ActorForOutbox",
|
||||
|
|
@ -212,7 +212,7 @@ func (f *federatingDB) ActorForOutbox(c context.Context, outboxIRI *url.URL) (ac
|
|||
return nil, fmt.Errorf("%s is not an outbox URI", outboxIRI.String())
|
||||
}
|
||||
acct := >smodel.Account{}
|
||||
if err := f.db.GetWhere([]db.Where{{Key: "outbox_uri", Value: outboxIRI.String()}}, acct); err != nil {
|
||||
if err := f.db.GetWhere(ctx, []db.Where{{Key: "outbox_uri", Value: outboxIRI.String()}}, acct); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
return nil, fmt.Errorf("no actor found that corresponds to outbox %s", outboxIRI.String())
|
||||
}
|
||||
|
|
@ -224,7 +224,7 @@ func (f *federatingDB) ActorForOutbox(c context.Context, outboxIRI *url.URL) (ac
|
|||
// ActorForInbox fetches the actor's IRI for the given outbox IRI.
|
||||
//
|
||||
// The library makes this call only after acquiring a lock first.
|
||||
func (f *federatingDB) ActorForInbox(c context.Context, inboxIRI *url.URL) (actorIRI *url.URL, err error) {
|
||||
func (f *federatingDB) ActorForInbox(ctx context.Context, inboxIRI *url.URL) (actorIRI *url.URL, err error) {
|
||||
l := f.log.WithFields(
|
||||
logrus.Fields{
|
||||
"func": "ActorForInbox",
|
||||
|
|
@ -237,7 +237,7 @@ func (f *federatingDB) ActorForInbox(c context.Context, inboxIRI *url.URL) (acto
|
|||
return nil, fmt.Errorf("%s is not an inbox URI", inboxIRI.String())
|
||||
}
|
||||
acct := >smodel.Account{}
|
||||
if err := f.db.GetWhere([]db.Where{{Key: "inbox_uri", Value: inboxIRI.String()}}, acct); err != nil {
|
||||
if err := f.db.GetWhere(ctx, []db.Where{{Key: "inbox_uri", Value: inboxIRI.String()}}, acct); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
return nil, fmt.Errorf("no actor found that corresponds to inbox %s", inboxIRI.String())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue