mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-28 04:33:32 -06:00
[chore] move client/federator workerpools to Workers{} (#1575)
* replace concurrency worker pools with base models in State.Workers, update code and tests accordingly * improve code comment * change back testrig default log level * un-comment-out TestAnnounceTwice() and fix --------- Signed-off-by: kim <grufwub@gmail.com> Reviewed-by: tobi
This commit is contained in:
parent
24cec4e7aa
commit
baf933cb9f
130 changed files with 1037 additions and 1083 deletions
|
|
@ -65,7 +65,7 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
|
|||
if uris.IsFollowPath(acceptedObjectIRI) {
|
||||
// ACCEPT FOLLOW
|
||||
gtsFollowRequest := >smodel.FollowRequest{}
|
||||
if err := f.db.GetWhere(ctx, []db.Where{{Key: "uri", Value: acceptedObjectIRI.String()}}, gtsFollowRequest); err != nil {
|
||||
if err := f.state.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)
|
||||
}
|
||||
|
||||
|
|
@ -73,12 +73,12 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
|
|||
if gtsFollowRequest.AccountID != receivingAccount.ID {
|
||||
return errors.New("ACCEPT: follow object account and inbox account were not the same")
|
||||
}
|
||||
follow, err := f.db.AcceptFollowRequest(ctx, gtsFollowRequest.AccountID, gtsFollowRequest.TargetAccountID)
|
||||
follow, err := f.state.DB.AcceptFollowRequest(ctx, gtsFollowRequest.AccountID, gtsFollowRequest.TargetAccountID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f.fedWorker.Queue(messages.FromFederator{
|
||||
f.state.Workers.EnqueueFederator(ctx, messages.FromFederator{
|
||||
APObjectType: ap.ActivityFollow,
|
||||
APActivityType: ap.ActivityAccept,
|
||||
GTSModel: follow,
|
||||
|
|
@ -108,12 +108,12 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
|
|||
if gtsFollow.AccountID != receivingAccount.ID {
|
||||
return errors.New("ACCEPT: follow object account and inbox account were not the same")
|
||||
}
|
||||
follow, err := f.db.AcceptFollowRequest(ctx, gtsFollow.AccountID, gtsFollow.TargetAccountID)
|
||||
follow, err := f.state.DB.AcceptFollowRequest(ctx, gtsFollow.AccountID, gtsFollow.TargetAccountID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f.fedWorker.Queue(messages.FromFederator{
|
||||
f.state.Workers.EnqueueFederator(ctx, messages.FromFederator{
|
||||
APObjectType: ap.ActivityFollow,
|
||||
APActivityType: ap.ActivityAccept,
|
||||
GTSModel: follow,
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func (f *federatingDB) Announce(ctx context.Context, announce vocab.ActivityStre
|
|||
}
|
||||
|
||||
// it's a new announce so pass it back to the processor async for dereferencing etc
|
||||
f.fedWorker.Queue(messages.FromFederator{
|
||||
f.state.Workers.EnqueueFederator(ctx, messages.FromFederator{
|
||||
APObjectType: ap.ActivityAnnounce,
|
||||
APActivityType: ap.ActivityCreate,
|
||||
GTSModel: boost,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/superseriousbusiness/activity/streams/vocab"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/id"
|
||||
)
|
||||
|
||||
type AnnounceTestSuite struct {
|
||||
|
|
@ -74,6 +75,13 @@ func (suite *AnnounceTestSuite) TestAnnounceTwice() {
|
|||
suite.True(ok)
|
||||
suite.Equal(announcingAccount.ID, boost.AccountID)
|
||||
|
||||
// Insert the boost-of status into the
|
||||
// DB cache to emulate processor handling
|
||||
boost.ID, _ = id.NewULIDFromTime(boost.CreatedAt)
|
||||
suite.state.Caches.GTS.Status().Store(boost, func() error {
|
||||
return nil
|
||||
})
|
||||
|
||||
// only the URI will be set on the boosted status because it still needs to be dereferenced
|
||||
suite.NotEmpty(boost.BoostOf.URI)
|
||||
|
||||
|
|
|
|||
|
|
@ -103,11 +103,11 @@ func (f *federatingDB) activityBlock(ctx context.Context, asType vocab.Type, rec
|
|||
|
||||
block.ID = id.NewULID()
|
||||
|
||||
if err := f.db.PutBlock(ctx, block); err != nil {
|
||||
if err := f.state.DB.PutBlock(ctx, block); err != nil {
|
||||
return fmt.Errorf("activityBlock: database error inserting block: %s", err)
|
||||
}
|
||||
|
||||
f.fedWorker.Queue(messages.FromFederator{
|
||||
f.state.Workers.EnqueueFederator(ctx, messages.FromFederator{
|
||||
APObjectType: ap.ActivityBlock,
|
||||
APActivityType: ap.ActivityCreate,
|
||||
GTSModel: block,
|
||||
|
|
@ -202,7 +202,7 @@ func (f *federatingDB) createNote(ctx context.Context, note vocab.ActivityStream
|
|||
return nil
|
||||
}
|
||||
// pass the note iri into the processor and have it do the dereferencing instead of doing it here
|
||||
f.fedWorker.Queue(messages.FromFederator{
|
||||
f.state.Workers.EnqueueFederator(ctx, messages.FromFederator{
|
||||
APObjectType: ap.ObjectNote,
|
||||
APActivityType: ap.ActivityCreate,
|
||||
APIri: id.GetIRI(),
|
||||
|
|
@ -226,7 +226,7 @@ func (f *federatingDB) createNote(ctx context.Context, note vocab.ActivityStream
|
|||
}
|
||||
status.ID = statusID
|
||||
|
||||
if err := f.db.PutStatus(ctx, status); err != nil {
|
||||
if err := f.state.DB.PutStatus(ctx, status); err != nil {
|
||||
if errors.Is(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.
|
||||
|
|
@ -236,7 +236,7 @@ func (f *federatingDB) createNote(ctx context.Context, note vocab.ActivityStream
|
|||
return fmt.Errorf("createNote: database error inserting status: %s", err)
|
||||
}
|
||||
|
||||
f.fedWorker.Queue(messages.FromFederator{
|
||||
f.state.Workers.EnqueueFederator(ctx, messages.FromFederator{
|
||||
APObjectType: ap.ObjectNote,
|
||||
APActivityType: ap.ActivityCreate,
|
||||
GTSModel: status,
|
||||
|
|
@ -263,11 +263,11 @@ func (f *federatingDB) activityFollow(ctx context.Context, asType vocab.Type, re
|
|||
|
||||
followRequest.ID = id.NewULID()
|
||||
|
||||
if err := f.db.Put(ctx, followRequest); err != nil {
|
||||
if err := f.state.DB.Put(ctx, followRequest); err != nil {
|
||||
return fmt.Errorf("activityFollow: database error inserting follow request: %s", err)
|
||||
}
|
||||
|
||||
f.fedWorker.Queue(messages.FromFederator{
|
||||
f.state.Workers.EnqueueFederator(ctx, messages.FromFederator{
|
||||
APObjectType: ap.ActivityFollow,
|
||||
APActivityType: ap.ActivityCreate,
|
||||
GTSModel: followRequest,
|
||||
|
|
@ -294,11 +294,11 @@ func (f *federatingDB) activityLike(ctx context.Context, asType vocab.Type, rece
|
|||
|
||||
fave.ID = id.NewULID()
|
||||
|
||||
if err := f.db.Put(ctx, fave); err != nil {
|
||||
if err := f.state.DB.Put(ctx, fave); err != nil {
|
||||
return fmt.Errorf("activityLike: database error inserting fave: %s", err)
|
||||
}
|
||||
|
||||
f.fedWorker.Queue(messages.FromFederator{
|
||||
f.state.Workers.EnqueueFederator(ctx, messages.FromFederator{
|
||||
APObjectType: ap.ActivityLike,
|
||||
APActivityType: ap.ActivityCreate,
|
||||
GTSModel: fave,
|
||||
|
|
@ -325,11 +325,11 @@ func (f *federatingDB) activityFlag(ctx context.Context, asType vocab.Type, rece
|
|||
|
||||
report.ID = id.NewULID()
|
||||
|
||||
if err := f.db.PutReport(ctx, report); err != nil {
|
||||
if err := f.state.DB.PutReport(ctx, report); err != nil {
|
||||
return fmt.Errorf("activityFlag: database error inserting report: %w", err)
|
||||
}
|
||||
|
||||
f.fedWorker.Queue(messages.FromFederator{
|
||||
f.state.Workers.EnqueueFederator(ctx, messages.FromFederator{
|
||||
APObjectType: ap.ActivityFlag,
|
||||
APActivityType: ap.ActivityCreate,
|
||||
GTSModel: report,
|
||||
|
|
|
|||
|
|
@ -24,9 +24,7 @@ import (
|
|||
"codeberg.org/gruf/go-mutexes"
|
||||
"github.com/superseriousbusiness/activity/pub"
|
||||
"github.com/superseriousbusiness/activity/streams/vocab"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/concurrency"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/state"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
||||
)
|
||||
|
||||
|
|
@ -43,17 +41,15 @@ type DB interface {
|
|||
// It doesn't care what the underlying implementation of the DB interface is, as long as it works.
|
||||
type federatingDB struct {
|
||||
locks mutexes.MutexMap
|
||||
db db.DB
|
||||
fedWorker *concurrency.WorkerPool[messages.FromFederator]
|
||||
state *state.State
|
||||
typeConverter typeutils.TypeConverter
|
||||
}
|
||||
|
||||
// New returns a DB interface using the given database and config
|
||||
func New(db db.DB, fedWorker *concurrency.WorkerPool[messages.FromFederator], tc typeutils.TypeConverter) DB {
|
||||
func New(state *state.State, tc typeutils.TypeConverter) DB {
|
||||
fdb := federatingDB{
|
||||
locks: mutexes.NewMap(-1, -1), // use defaults
|
||||
db: db,
|
||||
fedWorker: fedWorker,
|
||||
state: state,
|
||||
typeConverter: tc,
|
||||
}
|
||||
return &fdb
|
||||
|
|
|
|||
|
|
@ -51,9 +51,9 @@ 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...
|
||||
if s, err := f.db.GetStatusByURI(ctx, id.String()); err == nil && requestingAccount.ID == s.AccountID {
|
||||
if s, err := f.state.DB.GetStatusByURI(ctx, id.String()); err == nil && requestingAccount.ID == s.AccountID {
|
||||
l.Debugf("uri is for STATUS with id: %s", s.ID)
|
||||
f.fedWorker.Queue(messages.FromFederator{
|
||||
f.state.Workers.EnqueueFederator(ctx, messages.FromFederator{
|
||||
APObjectType: ap.ObjectNote,
|
||||
APActivityType: ap.ActivityDelete,
|
||||
GTSModel: s,
|
||||
|
|
@ -61,9 +61,9 @@ func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error {
|
|||
})
|
||||
}
|
||||
|
||||
if a, err := f.db.GetAccountByURI(ctx, id.String()); err == nil && requestingAccount.ID == a.ID {
|
||||
if a, err := f.state.DB.GetAccountByURI(ctx, id.String()); err == nil && requestingAccount.ID == a.ID {
|
||||
l.Debugf("uri is for ACCOUNT with id %s", a.ID)
|
||||
f.fedWorker.Queue(messages.FromFederator{
|
||||
f.state.Workers.EnqueueFederator(ctx, messages.FromFederator{
|
||||
APObjectType: ap.ObjectProfile,
|
||||
APActivityType: ap.ActivityDelete,
|
||||
GTSModel: a,
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/concurrency"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/federation/federatingdb"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/messages"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/state"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||
)
|
||||
|
|
@ -36,9 +36,9 @@ type FederatingDBTestSuite struct {
|
|||
suite.Suite
|
||||
db db.DB
|
||||
tc typeutils.TypeConverter
|
||||
fedWorker *concurrency.WorkerPool[messages.FromFederator]
|
||||
fromFederator chan messages.FromFederator
|
||||
federatingDB federatingdb.DB
|
||||
state state.State
|
||||
|
||||
testTokens map[string]*gtsmodel.Token
|
||||
testClients map[string]*gtsmodel.Client
|
||||
|
|
@ -66,22 +66,33 @@ func (suite *FederatingDBTestSuite) SetupTest() {
|
|||
testrig.InitTestConfig()
|
||||
testrig.InitTestLog()
|
||||
|
||||
suite.fedWorker = concurrency.NewWorkerPool[messages.FromFederator](-1, -1)
|
||||
suite.state.Caches.Init()
|
||||
testrig.StartWorkers(&suite.state)
|
||||
|
||||
suite.fromFederator = make(chan messages.FromFederator, 10)
|
||||
suite.fedWorker.SetProcessor(func(ctx context.Context, msg messages.FromFederator) error {
|
||||
suite.state.Workers.EnqueueFederator = func(ctx context.Context, msg messages.FromFederator) {
|
||||
suite.fromFederator <- msg
|
||||
return nil
|
||||
})
|
||||
_ = suite.fedWorker.Start()
|
||||
suite.db = testrig.NewTestDB()
|
||||
}
|
||||
|
||||
suite.db = testrig.NewTestDB(&suite.state)
|
||||
suite.testActivities = testrig.NewTestActivities(suite.testAccounts)
|
||||
suite.tc = testrig.NewTestTypeConverter(suite.db)
|
||||
suite.federatingDB = testrig.NewTestFederatingDB(suite.db, suite.fedWorker)
|
||||
suite.federatingDB = testrig.NewTestFederatingDB(&suite.state)
|
||||
testrig.StandardDBSetup(suite.db, suite.testAccounts)
|
||||
|
||||
suite.state.DB = suite.db
|
||||
}
|
||||
|
||||
func (suite *FederatingDBTestSuite) TearDownTest() {
|
||||
testrig.StandardDBTeardown(suite.db)
|
||||
testrig.StopWorkers(&suite.state)
|
||||
for suite.fromFederator != nil {
|
||||
select {
|
||||
case <-suite.fromFederator:
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func createTestContext(receivingAccount *gtsmodel.Account, requestingAccount *gtsmodel.Account) context.Context {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ func (f *federatingDB) Followers(ctx context.Context, actorIRI *url.URL) (follow
|
|||
return nil, err
|
||||
}
|
||||
|
||||
acctFollowers, err := f.db.GetAccountFollowedBy(ctx, acct.ID, false)
|
||||
acctFollowers, err := f.state.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)
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ func (f *federatingDB) Followers(ctx context.Context, actorIRI *url.URL) (follow
|
|||
iris := []*url.URL{}
|
||||
for _, follow := range acctFollowers {
|
||||
if follow.Account == nil {
|
||||
a, err := f.db.GetAccountByID(ctx, follow.AccountID)
|
||||
a, err := f.state.DB.GetAccountByID(ctx, follow.AccountID)
|
||||
if err != nil {
|
||||
errWrapped := fmt.Errorf("Followers: db error getting account id %s: %s", follow.AccountID, err)
|
||||
if err == db.ErrNoEntries {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func (f *federatingDB) Following(ctx context.Context, actorIRI *url.URL) (follow
|
|||
return nil, err
|
||||
}
|
||||
|
||||
acctFollowing, err := f.db.GetAccountFollows(ctx, acct.ID)
|
||||
acctFollowing, err := f.state.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)
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ func (f *federatingDB) Following(ctx context.Context, actorIRI *url.URL) (follow
|
|||
iris := []*url.URL{}
|
||||
for _, follow := range acctFollowing {
|
||||
if follow.TargetAccount == nil {
|
||||
a, err := f.db.GetAccountByID(ctx, follow.TargetAccountID)
|
||||
a, err := f.state.DB.GetAccountByID(ctx, follow.TargetAccountID)
|
||||
if err != nil {
|
||||
errWrapped := fmt.Errorf("Following: db error getting account id %s: %s", follow.TargetAccountID, err)
|
||||
if err == db.ErrNoEntries {
|
||||
|
|
|
|||
|
|
@ -39,13 +39,13 @@ func (f *federatingDB) Get(ctx context.Context, id *url.URL) (value vocab.Type,
|
|||
|
||||
switch {
|
||||
case uris.IsUserPath(id):
|
||||
acct, err := f.db.GetAccountByURI(ctx, id.String())
|
||||
acct, err := f.state.DB.GetAccountByURI(ctx, id.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return f.typeConverter.AccountToAS(ctx, acct)
|
||||
case uris.IsStatusesPath(id):
|
||||
status, err := f.db.GetStatusByURI(ctx, id.String())
|
||||
status, err := f.state.DB.GetStatusByURI(ctx, id.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,12 +85,12 @@ func (f *federatingDB) InboxesForIRI(c context.Context, iri *url.URL) (inboxIRIs
|
|||
return nil, fmt.Errorf("couldn't extract local account username from uri %s: %s", iri, err)
|
||||
}
|
||||
|
||||
account, err := f.db.GetAccountByUsernameDomain(c, localAccountUsername, "")
|
||||
account, err := f.state.DB.GetAccountByUsernameDomain(c, localAccountUsername, "")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("couldn't find local account with username %s: %s", localAccountUsername, err)
|
||||
}
|
||||
|
||||
follows, err := f.db.GetAccountFollowedBy(c, account.ID, false)
|
||||
follows, err := f.state.DB.GetAccountFollowedBy(c, account.ID, false)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("couldn't get followers of local account %s: %s", localAccountUsername, err)
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ func (f *federatingDB) InboxesForIRI(c context.Context, iri *url.URL) (inboxIRIs
|
|||
for _, follow := range follows {
|
||||
// make sure we retrieved the following account from the db
|
||||
if follow.Account == nil {
|
||||
followingAccount, err := f.db.GetAccountByID(c, follow.AccountID)
|
||||
followingAccount, err := f.state.DB.GetAccountByID(c, follow.AccountID)
|
||||
if err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
continue
|
||||
|
|
@ -126,7 +126,7 @@ func (f *federatingDB) InboxesForIRI(c context.Context, iri *url.URL) (inboxIRIs
|
|||
}
|
||||
|
||||
// check if this is just an account IRI...
|
||||
if account, err := f.db.GetAccountByURI(c, iri.String()); err == nil {
|
||||
if account, err := f.state.DB.GetAccountByURI(c, iri.String()); err == nil {
|
||||
// deliver to a shared inbox if we have that option
|
||||
var inbox string
|
||||
if config.GetInstanceDeliverToSharedInboxes() && account.SharedInboxURI != nil && *account.SharedInboxURI != "" {
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func (f *federatingDB) Owns(ctx 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(ctx, uid)
|
||||
status, err := f.state.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(ctx 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.GetAccountByUsernameDomain(ctx, username, ""); err != nil {
|
||||
if _, err := f.state.DB.GetAccountByUsernameDomain(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(ctx 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.GetAccountByUsernameDomain(ctx, username, ""); err != nil {
|
||||
if _, err := f.state.DB.GetAccountByUsernameDomain(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(ctx 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.GetAccountByUsernameDomain(ctx, username, ""); err != nil {
|
||||
if _, err := f.state.DB.GetAccountByUsernameDomain(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(ctx 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.GetAccountByUsernameDomain(ctx, username, ""); err != nil {
|
||||
if _, err := f.state.DB.GetAccountByUsernameDomain(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(ctx 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(ctx, likeID, >smodel.StatusFave{}); err != nil {
|
||||
if err := f.state.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(ctx 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.GetAccountByUsernameDomain(ctx, username, ""); err != nil {
|
||||
if _, err := f.state.DB.GetAccountByUsernameDomain(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(ctx 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(ctx, blockID, >smodel.Block{}); err != nil {
|
||||
if err := f.state.DB.GetByID(ctx, blockID, >smodel.Block{}); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
// there are no entries
|
||||
return false, nil
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func (f *federatingDB) Reject(ctx context.Context, reject vocab.ActivityStreamsR
|
|||
if uris.IsFollowPath(rejectedObjectIRI) {
|
||||
// REJECT FOLLOW
|
||||
gtsFollowRequest := >smodel.FollowRequest{}
|
||||
if err := f.db.GetWhere(ctx, []db.Where{{Key: "uri", Value: rejectedObjectIRI.String()}}, gtsFollowRequest); err != nil {
|
||||
if err := f.state.DB.GetWhere(ctx, []db.Where{{Key: "uri", Value: rejectedObjectIRI.String()}}, gtsFollowRequest); err != nil {
|
||||
return fmt.Errorf("Reject: couldn't get follow request with id %s from the database: %s", rejectedObjectIRI.String(), err)
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ func (f *federatingDB) Reject(ctx context.Context, reject vocab.ActivityStreamsR
|
|||
return errors.New("Reject: follow object account and inbox account were not the same")
|
||||
}
|
||||
|
||||
if _, err := f.db.RejectFollowRequest(ctx, gtsFollowRequest.AccountID, gtsFollowRequest.TargetAccountID); err != nil {
|
||||
if _, err := f.state.DB.RejectFollowRequest(ctx, gtsFollowRequest.AccountID, gtsFollowRequest.TargetAccountID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ func (f *federatingDB) Reject(ctx context.Context, reject vocab.ActivityStreamsR
|
|||
if gtsFollow.AccountID != receivingAccount.ID {
|
||||
return errors.New("Reject: follow object account and inbox account were not the same")
|
||||
}
|
||||
if _, err := f.db.RejectFollowRequest(ctx, gtsFollow.AccountID, gtsFollow.TargetAccountID); err != nil {
|
||||
if _, err := f.state.DB.RejectFollowRequest(ctx, gtsFollow.AccountID, gtsFollow.TargetAccountID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,11 +81,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(ctx, []db.Where{{Key: "uri", Value: gtsFollow.URI}}, >smodel.Follow{}); err != nil {
|
||||
if err := f.state.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(ctx, []db.Where{{Key: "uri", Value: gtsFollow.URI}}, >smodel.FollowRequest{}); err != nil {
|
||||
if err := f.state.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")
|
||||
|
|
@ -114,7 +114,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.DeleteBlockByURI(ctx, gtsBlock.URI); err != nil {
|
||||
if err := f.state.DB.DeleteBlockByURI(ctx, gtsBlock.URI); err != nil {
|
||||
return fmt.Errorf("UNDO: db error removing block: %s", err)
|
||||
}
|
||||
l.Debug("block undone")
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ func (f *federatingDB) Update(ctx context.Context, asType vocab.Type) error {
|
|||
|
||||
// pass to the processor for further updating of eg., avatar/header, emojis
|
||||
// the actual db insert/update will take place a bit later
|
||||
f.fedWorker.Queue(messages.FromFederator{
|
||||
f.state.Workers.EnqueueFederator(ctx, messages.FromFederator{
|
||||
APObjectType: ap.ObjectProfile,
|
||||
APActivityType: ap.ActivityUpdate,
|
||||
GTSModel: updatedAcct,
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ func (f *federatingDB) NewID(ctx context.Context, t vocab.Type) (idURL *url.URL,
|
|||
// 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(ctx, iter.GetIRI().String()); err == nil {
|
||||
if actorAccount, err := f.state.DB.GetAccountByURI(ctx, iter.GetIRI().String()); err == nil {
|
||||
newID, err := id.NewRandomULID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -238,7 +238,7 @@ func (f *federatingDB) getAccountForIRI(ctx context.Context, iri *url.URL) (*gts
|
|||
|
||||
switch {
|
||||
case uris.IsUserPath(iri):
|
||||
if acct, err = f.db.GetAccountByURI(ctx, iri.String()); err != nil {
|
||||
if acct, err = f.state.DB.GetAccountByURI(ctx, iri.String()); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
return nil, fmt.Errorf("no actor found that corresponds to uri %s", iri.String())
|
||||
}
|
||||
|
|
@ -246,7 +246,7 @@ func (f *federatingDB) getAccountForIRI(ctx context.Context, iri *url.URL) (*gts
|
|||
}
|
||||
return acct, nil
|
||||
case uris.IsInboxPath(iri):
|
||||
if err = f.db.GetWhere(ctx, []db.Where{{Key: "inbox_uri", Value: iri.String()}}, acct); err != nil {
|
||||
if err = f.state.DB.GetWhere(ctx, []db.Where{{Key: "inbox_uri", Value: iri.String()}}, acct); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
return nil, fmt.Errorf("no actor found that corresponds to inbox %s", iri.String())
|
||||
}
|
||||
|
|
@ -254,7 +254,7 @@ func (f *federatingDB) getAccountForIRI(ctx context.Context, iri *url.URL) (*gts
|
|||
}
|
||||
return acct, nil
|
||||
case uris.IsOutboxPath(iri):
|
||||
if err = f.db.GetWhere(ctx, []db.Where{{Key: "outbox_uri", Value: iri.String()}}, acct); err != nil {
|
||||
if err = f.state.DB.GetWhere(ctx, []db.Where{{Key: "outbox_uri", Value: iri.String()}}, acct); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
return nil, fmt.Errorf("no actor found that corresponds to outbox %s", iri.String())
|
||||
}
|
||||
|
|
@ -262,7 +262,7 @@ func (f *federatingDB) getAccountForIRI(ctx context.Context, iri *url.URL) (*gts
|
|||
}
|
||||
return acct, nil
|
||||
case uris.IsFollowersPath(iri):
|
||||
if err = f.db.GetWhere(ctx, []db.Where{{Key: "followers_uri", Value: iri.String()}}, acct); err != nil {
|
||||
if err = f.state.DB.GetWhere(ctx, []db.Where{{Key: "followers_uri", Value: iri.String()}}, acct); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
return nil, fmt.Errorf("no actor found that corresponds to followers_uri %s", iri.String())
|
||||
}
|
||||
|
|
@ -270,7 +270,7 @@ func (f *federatingDB) getAccountForIRI(ctx context.Context, iri *url.URL) (*gts
|
|||
}
|
||||
return acct, nil
|
||||
case uris.IsFollowingPath(iri):
|
||||
if err = f.db.GetWhere(ctx, []db.Where{{Key: "following_uri", Value: iri.String()}}, acct); err != nil {
|
||||
if err = f.state.DB.GetWhere(ctx, []db.Where{{Key: "following_uri", Value: iri.String()}}, acct); err != nil {
|
||||
if err == db.ErrNoEntries {
|
||||
return nil, fmt.Errorf("no actor found that corresponds to following_uri %s", iri.String())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue