[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:
kim
2023-03-01 18:26:53 +00:00
committed by GitHub
parent 24cec4e7aa
commit baf933cb9f
130 changed files with 1037 additions and 1083 deletions

View File

@ -30,7 +30,7 @@ import (
)
func (p *Processor) FollowRequestsGet(ctx context.Context, auth *oauth.Auth) ([]apimodel.Account, gtserror.WithCode) {
frs, err := p.db.GetAccountFollowRequests(ctx, auth.Account.ID)
frs, err := p.state.DB.GetAccountFollowRequests(ctx, auth.Account.ID)
if err != nil {
if err != db.ErrNoEntries {
return nil, gtserror.NewErrorInternalError(err)
@ -40,7 +40,7 @@ func (p *Processor) FollowRequestsGet(ctx context.Context, auth *oauth.Auth) ([]
accts := []apimodel.Account{}
for _, fr := range frs {
if fr.Account == nil {
frAcct, err := p.db.GetAccountByID(ctx, fr.AccountID)
frAcct, err := p.state.DB.GetAccountByID(ctx, fr.AccountID)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}
@ -57,13 +57,13 @@ func (p *Processor) FollowRequestsGet(ctx context.Context, auth *oauth.Auth) ([]
}
func (p *Processor) FollowRequestAccept(ctx context.Context, auth *oauth.Auth, accountID string) (*apimodel.Relationship, gtserror.WithCode) {
follow, err := p.db.AcceptFollowRequest(ctx, accountID, auth.Account.ID)
follow, err := p.state.DB.AcceptFollowRequest(ctx, accountID, auth.Account.ID)
if err != nil {
return nil, gtserror.NewErrorNotFound(err)
}
if follow.Account == nil {
followAccount, err := p.db.GetAccountByID(ctx, follow.AccountID)
followAccount, err := p.state.DB.GetAccountByID(ctx, follow.AccountID)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}
@ -71,14 +71,14 @@ func (p *Processor) FollowRequestAccept(ctx context.Context, auth *oauth.Auth, a
}
if follow.TargetAccount == nil {
followTargetAccount, err := p.db.GetAccountByID(ctx, follow.TargetAccountID)
followTargetAccount, err := p.state.DB.GetAccountByID(ctx, follow.TargetAccountID)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}
follow.TargetAccount = followTargetAccount
}
p.clientWorker.Queue(messages.FromClientAPI{
p.state.Workers.EnqueueClientAPI(ctx, messages.FromClientAPI{
APObjectType: ap.ActivityFollow,
APActivityType: ap.ActivityAccept,
GTSModel: follow,
@ -86,7 +86,7 @@ func (p *Processor) FollowRequestAccept(ctx context.Context, auth *oauth.Auth, a
TargetAccount: follow.TargetAccount,
})
gtsR, err := p.db.GetRelationship(ctx, auth.Account.ID, accountID)
gtsR, err := p.state.DB.GetRelationship(ctx, auth.Account.ID, accountID)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}
@ -100,13 +100,13 @@ func (p *Processor) FollowRequestAccept(ctx context.Context, auth *oauth.Auth, a
}
func (p *Processor) FollowRequestReject(ctx context.Context, auth *oauth.Auth, accountID string) (*apimodel.Relationship, gtserror.WithCode) {
followRequest, err := p.db.RejectFollowRequest(ctx, accountID, auth.Account.ID)
followRequest, err := p.state.DB.RejectFollowRequest(ctx, accountID, auth.Account.ID)
if err != nil {
return nil, gtserror.NewErrorNotFound(err)
}
if followRequest.Account == nil {
a, err := p.db.GetAccountByID(ctx, followRequest.AccountID)
a, err := p.state.DB.GetAccountByID(ctx, followRequest.AccountID)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}
@ -114,14 +114,14 @@ func (p *Processor) FollowRequestReject(ctx context.Context, auth *oauth.Auth, a
}
if followRequest.TargetAccount == nil {
a, err := p.db.GetAccountByID(ctx, followRequest.TargetAccountID)
a, err := p.state.DB.GetAccountByID(ctx, followRequest.TargetAccountID)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}
followRequest.TargetAccount = a
}
p.clientWorker.Queue(messages.FromClientAPI{
p.state.Workers.EnqueueClientAPI(ctx, messages.FromClientAPI{
APObjectType: ap.ActivityFollow,
APActivityType: ap.ActivityReject,
GTSModel: followRequest,
@ -129,7 +129,7 @@ func (p *Processor) FollowRequestReject(ctx context.Context, auth *oauth.Auth, a
TargetAccount: followRequest.TargetAccount,
})
gtsR, err := p.db.GetRelationship(ctx, auth.Account.ID, accountID)
gtsR, err := p.state.DB.GetRelationship(ctx, auth.Account.ID, accountID)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}