diff options
author | 2022-11-15 18:45:15 +0000 | |
---|---|---|
committer | 2022-11-15 18:45:15 +0000 | |
commit | 8598dea98b872647393117704659878d9b38d4fc (patch) | |
tree | 1940168912dc7f54af723439dbc9f6e0a42f30ae /internal/db/bundb/admin.go | |
parent | [docs] Both HTTP proxies and NAT can cause rate limiting issues (#1053) (diff) | |
download | gotosocial-8598dea98b872647393117704659878d9b38d4fc.tar.xz |
[chore] update database caching library (#1040)
* convert most of the caches to use result.Cache{}
* add caching of emojis
* fix issues causing failing tests
* update go-cache/v2 instances with v3
* fix getnotification
* add a note about the left-in StatusCreate comment
* update EmojiCategory db access to use new result.Cache{}
* fix possible panic in getstatusparents
* further proof that kim is not stinky
Diffstat (limited to 'internal/db/bundb/admin.go')
-rw-r--r-- | internal/db/bundb/admin.go | 33 |
1 files changed, 10 insertions, 23 deletions
diff --git a/internal/db/bundb/admin.go b/internal/db/bundb/admin.go index 44861a4bb..4d750581c 100644 --- a/internal/db/bundb/admin.go +++ b/internal/db/bundb/admin.go @@ -29,7 +29,6 @@ import ( "time" "github.com/superseriousbusiness/gotosocial/internal/ap" - "github.com/superseriousbusiness/gotosocial/internal/cache" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" @@ -44,9 +43,9 @@ import ( const rsaKeyBits = 2048 type adminDB struct { - conn *DBConn - userCache *cache.UserCache - accountCache *cache.AccountCache + conn *DBConn + accounts *accountDB + users *userDB } func (a *adminDB) IsUsernameAvailable(ctx context.Context, username string) (bool, db.Error) { @@ -140,13 +139,9 @@ func (a *adminDB) NewSignup(ctx context.Context, username string, reason string, } // insert the new account! - if _, err = a.conn. - NewInsert(). - Model(acct). - Exec(ctx); err != nil { - return nil, a.conn.ProcessError(err) + if err := a.accounts.PutAccount(ctx, acct); err != nil { + return nil, err } - a.accountCache.Put(acct) } // we either created or already had an account by now, @@ -190,13 +185,9 @@ func (a *adminDB) NewSignup(ctx context.Context, username string, reason string, } // insert the user! - if _, err = a.conn. - NewInsert(). - Model(u). - Exec(ctx); err != nil { - return nil, a.conn.ProcessError(err) + if err := a.users.PutUser(ctx, u); err != nil { + return nil, err } - a.userCache.Put(u) return u, nil } @@ -249,15 +240,11 @@ func (a *adminDB) CreateInstanceAccount(ctx context.Context) db.Error { FeaturedCollectionURI: newAccountURIs.CollectionURI, } - insertQ := a.conn. - NewInsert(). - Model(acct) - - if _, err := insertQ.Exec(ctx); err != nil { - return a.conn.ProcessError(err) + // insert the new account! + if err := a.accounts.PutAccount(ctx, acct); err != nil { + return err } - a.accountCache.Put(acct) log.Infof("instance account %s CREATED with id %s", username, acct.ID) return nil } |