summaryrefslogtreecommitdiff
path: root/internal/processing
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-10-03 10:46:11 +0200
committerLibravatar GitHub <noreply@github.com>2022-10-03 10:46:11 +0200
commit56f53a2a6f85876485e2ae67d48b78b448caed6e (patch)
tree9bd8d3fcaffd515d3dc90ff22c6cee17e8d0b073 /internal/processing
parent[feature] Enlarge active/hovered custom emojis in statuses (#877) (diff)
downloadgotosocial-56f53a2a6f85876485e2ae67d48b78b448caed6e.tar.xz
[performance] add user cache and database (#879)
* go fmt * add + use user cache and database * fix import * update tests * remove unused relation
Diffstat (limited to 'internal/processing')
-rw-r--r--internal/processing/account/delete.go19
-rw-r--r--internal/processing/fromclientapi.go5
-rw-r--r--internal/processing/fromfederator_test.go2
-rw-r--r--internal/processing/instance.go4
-rw-r--r--internal/processing/streaming/authorize.go4
-rw-r--r--internal/processing/user/emailconfirm.go4
6 files changed, 20 insertions, 18 deletions
diff --git a/internal/processing/account/delete.go b/internal/processing/account/delete.go
index 3a5a9c622..3758a4000 100644
--- a/internal/processing/account/delete.go
+++ b/internal/processing/account/delete.go
@@ -70,13 +70,14 @@ func (p *processor) Delete(ctx context.Context, account *gtsmodel.Account, origi
// 1. Delete account's application(s), clients, and oauth tokens
// we only need to do this step for local account since remote ones won't have any tokens or applications on our server
+ var user *gtsmodel.User
if account.Domain == "" {
// see if we can get a user for this account
- u := &gtsmodel.User{}
- if err := p.db.GetWhere(ctx, []db.Where{{Key: "account_id", Value: account.ID}}, u); err == nil {
+ var err error
+ if user, err = p.db.GetUserByAccountID(ctx, account.ID); err == nil {
// we got one! select all tokens with the user's ID
tokens := []*gtsmodel.Token{}
- if err := p.db.GetWhere(ctx, []db.Where{{Key: "user_id", Value: u.ID}}, &tokens); err == nil {
+ if err := p.db.GetWhere(ctx, []db.Where{{Key: "user_id", Value: user.ID}}, &tokens); err == nil {
// we have some tokens to delete
for _, t := range tokens {
// delete client(s) associated with this token
@@ -240,9 +241,11 @@ selectStatusesLoop:
// TODO
// 16. Delete account's user
- l.Debug("deleting account user")
- if err := p.db.DeleteWhere(ctx, []db.Where{{Key: "account_id", Value: account.ID}}, &gtsmodel.User{}); err != nil {
- return gtserror.NewErrorInternalError(err)
+ if user != nil {
+ l.Debug("deleting account user")
+ if err := p.db.DeleteUserByID(ctx, user.ID); err != nil {
+ return gtserror.NewErrorInternalError(err)
+ }
}
// 17. Delete account's timeline
@@ -288,8 +291,8 @@ func (p *processor) DeleteLocal(ctx context.Context, account *gtsmodel.Account,
if form.DeleteOriginID == account.ID {
// the account owner themself has requested deletion via the API, get their user from the db
- user := &gtsmodel.User{}
- if err := p.db.GetWhere(ctx, []db.Where{{Key: "account_id", Value: account.ID}}, user); err != nil {
+ user, err := p.db.GetUserByAccountID(ctx, account.ID)
+ if err != nil {
return gtserror.NewErrorInternalError(err)
}
diff --git a/internal/processing/fromclientapi.go b/internal/processing/fromclientapi.go
index d7c9c5d82..a688e3732 100644
--- a/internal/processing/fromclientapi.go
+++ b/internal/processing/fromclientapi.go
@@ -29,7 +29,6 @@ import (
"github.com/superseriousbusiness/activity/pub"
"github.com/superseriousbusiness/activity/streams"
"github.com/superseriousbusiness/gotosocial/internal/ap"
- "github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/messages"
@@ -138,8 +137,8 @@ func (p *processor) processCreateAccountFromClientAPI(ctx context.Context, clien
}
// get the user this account belongs to
- user := &gtsmodel.User{}
- if err := p.db.GetWhere(ctx, []db.Where{{Key: "account_id", Value: account.ID}}, user); err != nil {
+ user, err := p.db.GetUserByAccountID(ctx, account.ID)
+ if err != nil {
return err
}
diff --git a/internal/processing/fromfederator_test.go b/internal/processing/fromfederator_test.go
index 9337482c4..22d0ba9f4 100644
--- a/internal/processing/fromfederator_test.go
+++ b/internal/processing/fromfederator_test.go
@@ -370,7 +370,7 @@ func (suite *FromFederatorTestSuite) TestProcessAccountDelete() {
// no statuses from foss satan should be left in the database
if !testrig.WaitFor(func() bool {
s, err := suite.db.GetAccountStatuses(ctx, deletedAccount.ID, 0, false, false, "", "", false, false, false)
- return s == nil && err == db.ErrNoEntries
+ return s == nil && err == db.ErrNoEntries
}) {
suite.FailNow("timeout waiting for statuses to be deleted")
}
diff --git a/internal/processing/instance.go b/internal/processing/instance.go
index b7418659a..32a4de6f0 100644
--- a/internal/processing/instance.go
+++ b/internal/processing/instance.go
@@ -142,8 +142,8 @@ func (p *processor) InstancePatch(ctx context.Context, form *apimodel.InstanceSe
return nil, gtserror.NewErrorBadRequest(err, fmt.Sprintf("account with username %s not retrievable", *form.ContactUsername))
}
// make sure it has a user associated with it
- contactUser := &gtsmodel.User{}
- if err := p.db.GetWhere(ctx, []db.Where{{Key: "account_id", Value: contactAccount.ID}}, contactUser); err != nil {
+ contactUser, err := p.db.GetUserByAccountID(ctx, contactAccount.ID)
+ if err != nil {
return nil, gtserror.NewErrorBadRequest(err, fmt.Sprintf("user for account with username %s not retrievable", *form.ContactUsername))
}
// suspended accounts cannot be contact accounts
diff --git a/internal/processing/streaming/authorize.go b/internal/processing/streaming/authorize.go
index 70e4741e1..cb152b676 100644
--- a/internal/processing/streaming/authorize.go
+++ b/internal/processing/streaming/authorize.go
@@ -40,8 +40,8 @@ func (p *processor) AuthorizeStreamingRequest(ctx context.Context, accessToken s
return nil, gtserror.NewErrorUnauthorized(err)
}
- user := &gtsmodel.User{}
- if err := p.db.GetByID(ctx, uid, user); err != nil {
+ user, err := p.db.GetUserByID(ctx, uid)
+ if err != nil {
if err == db.ErrNoEntries {
err := fmt.Errorf("no user found for validated uid %s", uid)
return nil, gtserror.NewErrorUnauthorized(err)
diff --git a/internal/processing/user/emailconfirm.go b/internal/processing/user/emailconfirm.go
index 6bffce7d9..5a68383b8 100644
--- a/internal/processing/user/emailconfirm.go
+++ b/internal/processing/user/emailconfirm.go
@@ -89,8 +89,8 @@ func (p *processor) ConfirmEmail(ctx context.Context, token string) (*gtsmodel.U
return nil, gtserror.NewErrorNotFound(errors.New("no token provided"))
}
- user := &gtsmodel.User{}
- if err := p.db.GetWhere(ctx, []db.Where{{Key: "confirmation_token", Value: token}}, user); err != nil {
+ user, err := p.db.GetUserByConfirmationToken(ctx, token)
+ if err != nil {
if err == db.ErrNoEntries {
return nil, gtserror.NewErrorNotFound(err)
}