diff options
author | 2021-08-29 15:41:41 +0100 | |
---|---|---|
committer | 2021-08-29 16:41:41 +0200 | |
commit | ed462245730bd7832019bd43e0bc1c9d1c055e8e (patch) | |
tree | 1caad78ea6aabf5ea93c93a8ade97176b4889500 /internal/db/bundb/admin.go | |
parent | Mention fixup (#167) (diff) | |
download | gotosocial-ed462245730bd7832019bd43e0bc1c9d1c055e8e.tar.xz |
Add SQLite support, fix un-thread-safe DB caches, small performance f… (#172)
* Add SQLite support, fix un-thread-safe DB caches, small performance fixes
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* add SQLite licenses to README
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* appease the linter, and fix my dumbass-ery
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* make requested changes
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
* add back comment
Signed-off-by: kim (grufwub) <grufwub@gmail.com>
Diffstat (limited to 'internal/db/bundb/admin.go')
-rw-r--r-- | internal/db/bundb/admin.go | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/internal/db/bundb/admin.go b/internal/db/bundb/admin.go index d43501444..6a51ffeb1 100644 --- a/internal/db/bundb/admin.go +++ b/internal/db/bundb/admin.go @@ -29,20 +29,17 @@ import ( "strings" "time" - "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/id" "github.com/superseriousbusiness/gotosocial/internal/util" - "github.com/uptrace/bun" "golang.org/x/crypto/bcrypt" ) type adminDB struct { config *config.Config - conn *bun.DB - log *logrus.Logger + conn *DBConn } func (a *adminDB) IsUsernameAvailable(ctx context.Context, username string) (bool, db.Error) { @@ -52,7 +49,7 @@ func (a *adminDB) IsUsernameAvailable(ctx context.Context, username string) (boo Where("username = ?", username). Where("domain = ?", nil) - return notExists(ctx, q) + return a.conn.NotExists(ctx, q) } func (a *adminDB) IsEmailAvailable(ctx context.Context, email string) (bool, db.Error) { @@ -72,7 +69,7 @@ func (a *adminDB) IsEmailAvailable(ctx context.Context, email string) (bool, db. // fail because we found something return false, fmt.Errorf("email domain %s is blocked", domain) } else if err != sql.ErrNoRows { - return false, processErrorResponse(err) + return false, a.conn.ProcessError(err) } // check if this email is associated with a user already @@ -82,13 +79,13 @@ func (a *adminDB) IsEmailAvailable(ctx context.Context, email string) (bool, db. Where("email = ?", email). WhereOr("unconfirmed_email = ?", email) - return notExists(ctx, q) + return a.conn.NotExists(ctx, q) } func (a *adminDB) NewSignup(ctx context.Context, username string, reason string, requireApproval bool, email string, password string, signUpIP net.IP, locale string, appID string, emailVerified bool, admin bool) (*gtsmodel.User, db.Error) { key, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { - a.log.Errorf("error creating new rsa key: %s", err) + a.conn.log.Errorf("error creating new rsa key: %s", err) return nil, err } @@ -128,7 +125,7 @@ func (a *adminDB) NewSignup(ctx context.Context, username string, reason string, NewInsert(). Model(acct). Exec(ctx); err != nil { - return nil, err + return nil, a.conn.ProcessError(err) } } @@ -167,7 +164,7 @@ func (a *adminDB) NewSignup(ctx context.Context, username string, reason string, NewInsert(). Model(u). Exec(ctx); err != nil { - return nil, err + return nil, a.conn.ProcessError(err) } return u, nil @@ -184,15 +181,15 @@ func (a *adminDB) CreateInstanceAccount(ctx context.Context) db.Error { WhereGroup(" AND ", whereEmptyOrNull("domain")) count, err := existsQ.Count(ctx) if err != nil && count == 1 { - a.log.Infof("instance account %s already exists", username) + a.conn.log.Infof("instance account %s already exists", username) return nil } else if err != sql.ErrNoRows { - return processErrorResponse(err) + return a.conn.ProcessError(err) } key, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { - a.log.Errorf("error creating new rsa key: %s", err) + a.conn.log.Errorf("error creating new rsa key: %s", err) return err } @@ -224,10 +221,10 @@ func (a *adminDB) CreateInstanceAccount(ctx context.Context) db.Error { Model(acct) if _, err := insertQ.Exec(ctx); err != nil { - return err + return a.conn.ProcessError(err) } - a.log.Infof("instance account %s CREATED with id %s", username, acct.ID) + a.conn.log.Infof("instance account %s CREATED with id %s", username, acct.ID) return nil } @@ -240,12 +237,12 @@ func (a *adminDB) CreateInstanceInstance(ctx context.Context) db.Error { Model(>smodel.Instance{}). Where("domain = ?", domain) - exists, err := exists(ctx, q) + exists, err := a.conn.Exists(ctx, q) if err != nil { return err } if exists { - a.log.Infof("instance entry already exists") + a.conn.log.Infof("instance entry already exists") return nil } @@ -266,10 +263,10 @@ func (a *adminDB) CreateInstanceInstance(ctx context.Context) db.Error { Model(i) _, err = insertQ.Exec(ctx) - err = processErrorResponse(err) - - if err == nil { - a.log.Infof("created instance instance %s with id %s", domain, i.ID) + if err != nil { + return a.conn.ProcessError(err) } - return err + + a.conn.log.Infof("created instance instance %s with id %s", domain, i.ID) + return nil } |