diff options
author | 2021-12-07 13:31:39 +0100 | |
---|---|---|
committer | 2021-12-07 13:31:39 +0100 | |
commit | 0884f89431cd26bcc9674b3b7ab628b090f5881e (patch) | |
tree | cdd3b3f77f780a8b59d075dbcc3d4d013811e405 /internal/db | |
parent | Update dependencies (#333) (diff) | |
download | gotosocial-0884f89431cd26bcc9674b3b7ab628b090f5881e.tar.xz |
Implement Cobra CLI tooling, Viper config tooling (#336)
* start pulling out + replacing urfave and config
* replace many many instances of config
* move more stuff => viper
* properly remove urfave
* move some flags to root command
* add testrig commands to root
* alias config file keys
* start adding cli parsing tests
* reorder viper init
* remove config path alias
* fmt
* change config file keys to non-nested
* we're more or less in business now
* tidy up the common func
* go fmt
* get tests passing again
* add note about the cliparsing tests
* reorganize
* update docs with changes
* structure cmd dir better
* rename + move some files around
* fix dangling comma
Diffstat (limited to 'internal/db')
-rw-r--r-- | internal/db/bundb/account.go | 9 | ||||
-rw-r--r-- | internal/db/bundb/admin.go | 25 | ||||
-rw-r--r-- | internal/db/bundb/basic.go | 4 | ||||
-rw-r--r-- | internal/db/bundb/bundb.go | 149 | ||||
-rw-r--r-- | internal/db/bundb/bundb_test.go | 8 | ||||
-rw-r--r-- | internal/db/bundb/domain.go | 4 | ||||
-rw-r--r-- | internal/db/bundb/instance.go | 14 | ||||
-rw-r--r-- | internal/db/bundb/media.go | 4 | ||||
-rw-r--r-- | internal/db/bundb/mention.go | 6 | ||||
-rw-r--r-- | internal/db/bundb/notification.go | 6 | ||||
-rw-r--r-- | internal/db/bundb/relationship.go | 4 | ||||
-rw-r--r-- | internal/db/bundb/session.go | 4 | ||||
-rw-r--r-- | internal/db/bundb/status.go | 6 | ||||
-rw-r--r-- | internal/db/bundb/timeline.go | 4 |
14 files changed, 124 insertions, 123 deletions
diff --git a/internal/db/bundb/account.go b/internal/db/bundb/account.go index 9c9dcfc6a..ab6ec2b7c 100644 --- a/internal/db/bundb/account.go +++ b/internal/db/bundb/account.go @@ -24,6 +24,7 @@ import ( "fmt" "time" + "github.com/spf13/viper" "github.com/superseriousbusiness/gotosocial/internal/cache" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -32,9 +33,8 @@ import ( ) type accountDB struct { - config *config.Config - conn *DBConn - cache *cache.AccountCache + conn *DBConn + cache *cache.AccountCache } func (a *accountDB) newAccountQ(account *gtsmodel.Account) *bun.SelectQuery { @@ -132,8 +132,9 @@ func (a *accountDB) GetInstanceAccount(ctx context.Context, domain string) (*gts Where("account.username = ?", domain). Where("account.domain = ?", domain) } else { + host := viper.GetString(config.Keys.Host) q = q. - Where("account.username = ?", a.config.Host). + Where("account.username = ?", host). WhereGroup(" AND ", whereEmptyOrNull("domain")) } diff --git a/internal/db/bundb/admin.go b/internal/db/bundb/admin.go index accdf7e53..4b05fdd56 100644 --- a/internal/db/bundb/admin.go +++ b/internal/db/bundb/admin.go @@ -30,6 +30,7 @@ import ( "time" "github.com/sirupsen/logrus" + "github.com/spf13/viper" "github.com/superseriousbusiness/gotosocial/internal/ap" "github.com/superseriousbusiness/gotosocial/internal/config" @@ -41,8 +42,7 @@ import ( ) type adminDB struct { - config *config.Config - conn *DBConn + conn *DBConn } func (a *adminDB) IsUsernameAvailable(ctx context.Context, username string) (bool, db.Error) { @@ -101,7 +101,7 @@ func (a *adminDB) NewSignup(ctx context.Context, username string, reason string, Scan(ctx) if err != nil { // we just don't have an account yet create one - newAccountURIs := util.GenerateURIsForAccount(username, a.config.Protocol, a.config.Host) + newAccountURIs := util.GenerateURIsForAccount(username) newAccountID, err := id.NewRandomULID() if err != nil { return nil, err @@ -176,7 +176,7 @@ func (a *adminDB) NewSignup(ctx context.Context, username string, reason string, } func (a *adminDB) CreateInstanceAccount(ctx context.Context) db.Error { - username := a.config.Host + username := viper.GetString(config.Keys.Host) q := a.conn. NewSelect(). @@ -204,10 +204,10 @@ func (a *adminDB) CreateInstanceAccount(ctx context.Context) db.Error { return err } - newAccountURIs := util.GenerateURIsForAccount(username, a.config.Protocol, a.config.Host) + newAccountURIs := util.GenerateURIsForAccount(username) acct := >smodel.Account{ ID: aID, - Username: a.config.Host, + Username: username, DisplayName: username, URL: newAccountURIs.UserURL, PrivateKey: key, @@ -235,13 +235,14 @@ func (a *adminDB) CreateInstanceAccount(ctx context.Context) db.Error { } func (a *adminDB) CreateInstanceInstance(ctx context.Context) db.Error { - domain := a.config.Host + protocol := viper.GetString(config.Keys.Protocol) + host := viper.GetString(config.Keys.Host) // check if instance entry already exists q := a.conn. NewSelect(). Model(>smodel.Instance{}). - Where("domain = ?", domain) + Where("domain = ?", host) exists, err := a.conn.Exists(ctx, q) if err != nil { @@ -259,9 +260,9 @@ func (a *adminDB) CreateInstanceInstance(ctx context.Context) db.Error { i := >smodel.Instance{ ID: iID, - Domain: domain, - Title: domain, - URI: fmt.Sprintf("%s://%s", a.config.Protocol, a.config.Host), + Domain: host, + Title: host, + URI: fmt.Sprintf("%s://%s", protocol, host), } insertQ := a.conn. @@ -273,6 +274,6 @@ func (a *adminDB) CreateInstanceInstance(ctx context.Context) db.Error { return a.conn.ProcessError(err) } - logrus.Infof("created instance instance %s with id %s", domain, i.ID) + logrus.Infof("created instance instance %s with id %s", host, i.ID) return nil } diff --git a/internal/db/bundb/basic.go b/internal/db/bundb/basic.go index 2ff8dcb9b..a4cff4202 100644 --- a/internal/db/bundb/basic.go +++ b/internal/db/bundb/basic.go @@ -24,15 +24,13 @@ import ( "github.com/sirupsen/logrus" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/uptrace/bun" ) type basicDB struct { - config *config.Config - conn *DBConn + conn *DBConn } func (b *basicDB) Put(ctx context.Context, i interface{}) db.Error { diff --git a/internal/db/bundb/bundb.go b/internal/db/bundb/bundb.go index 4634f1981..bb159fad8 100644 --- a/internal/db/bundb/bundb.go +++ b/internal/db/bundb/bundb.go @@ -35,6 +35,7 @@ import ( "github.com/jackc/pgx/v4" "github.com/jackc/pgx/v4/stdlib" "github.com/sirupsen/logrus" + "github.com/spf13/viper" "github.com/superseriousbusiness/gotosocial/internal/cache" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -52,6 +53,17 @@ import ( const ( dbTypePostgres = "postgres" dbTypeSqlite = "sqlite" + + // dbTLSModeDisable does not attempt to make a TLS connection to the database. + dbTLSModeDisable = "disable" + // dbTLSModeEnable attempts to make a TLS connection to the database, but doesn't fail if + // the certificate passed by the database isn't verified. + dbTLSModeEnable = "enable" + // dbTLSModeRequire attempts to make a TLS connection to the database, and requires + // that the certificate presented by the database is valid. + dbTLSModeRequire = "require" + // dbTLSModeUnset means that the TLS mode has not been set. + dbTLSModeUnset = "" ) var registerTables = []interface{}{ @@ -73,8 +85,7 @@ type bunDBService struct { db.Session db.Status db.Timeline - config *config.Config - conn *DBConn + conn *DBConn } func doMigration(ctx context.Context, db *bun.DB) error { @@ -105,22 +116,24 @@ func doMigration(ctx context.Context, db *bun.DB) error { // NewBunDBService returns a bunDB derived from the provided config, which implements the go-fed DB interface. // Under the hood, it uses https://github.com/uptrace/bun to create and maintain a database connection. -func NewBunDBService(ctx context.Context, c *config.Config) (db.DB, error) { +func NewBunDBService(ctx context.Context) (db.DB, error) { var conn *DBConn var err error - switch strings.ToLower(c.DBConfig.Type) { + dbType := strings.ToLower(viper.GetString(config.Keys.DbType)) + + switch dbType { case dbTypePostgres: - conn, err = pgConn(ctx, c) + conn, err = pgConn(ctx) if err != nil { return nil, err } case dbTypeSqlite: - conn, err = sqliteConn(ctx, c) + conn, err = sqliteConn(ctx) if err != nil { return nil, err } default: - return nil, fmt.Errorf("database type %s not supported for bundb", strings.ToLower(c.DBConfig.Type)) + return nil, fmt.Errorf("database type %s not supported for bundb", dbType) } // add a hook to just log queries and the time they take @@ -142,76 +155,66 @@ func NewBunDBService(ctx context.Context, c *config.Config) (db.DB, error) { return nil, fmt.Errorf("db migration error: %s", err) } - accounts := &accountDB{config: c, conn: conn, cache: cache.NewAccountCache()} + accounts := &accountDB{conn: conn, cache: cache.NewAccountCache()} ps := &bunDBService{ Account: accounts, Admin: &adminDB{ - config: c, - conn: conn, + conn: conn, }, Basic: &basicDB{ - config: c, - conn: conn, + conn: conn, }, Domain: &domainDB{ - config: c, - conn: conn, + conn: conn, }, Instance: &instanceDB{ - config: c, - conn: conn, + conn: conn, }, Media: &mediaDB{ - config: c, - conn: conn, + conn: conn, }, Mention: &mentionDB{ - config: c, - conn: conn, - cache: ttlcache.NewCache(), + conn: conn, + cache: ttlcache.NewCache(), }, Notification: ¬ificationDB{ - config: c, - conn: conn, - cache: ttlcache.NewCache(), + conn: conn, + cache: ttlcache.NewCache(), }, Relationship: &relationshipDB{ - config: c, - conn: conn, + conn: conn, }, Session: &sessionDB{ - config: c, - conn: conn, + conn: conn, }, Status: &statusDB{ - config: c, conn: conn, cache: cache.NewStatusCache(), accounts: accounts, }, Timeline: &timelineDB{ - config: c, - conn: conn, + conn: conn, }, - config: c, - conn: conn, + conn: conn, } // we can confidently return this useable service now return ps, nil } -func sqliteConn(ctx context.Context, c *config.Config) (*DBConn, error) { +func sqliteConn(ctx context.Context) (*DBConn, error) { + dbAddress := viper.GetString(config.Keys.DbAddress) + // Drop anything fancy from DB address - c.DBConfig.Address = strings.Split(c.DBConfig.Address, "?")[0] - c.DBConfig.Address = strings.TrimPrefix(c.DBConfig.Address, "file:") + dbAddress = strings.Split(dbAddress, "?")[0] + dbAddress = strings.TrimPrefix(dbAddress, "file:") // Append our own SQLite preferences - c.DBConfig.Address = "file:" + c.DBConfig.Address + "?cache=shared" + dbAddress = "file:" + dbAddress + "?cache=shared" // Open new DB instance - sqldb, err := sql.Open("sqlite", c.DBConfig.Address) + sqldb, err := sql.Open("sqlite", dbAddress) if err != nil { if errWithCode, ok := err.(*sqlite.Error); ok { err = errors.New(sqlite.ErrorCodeString[errWithCode.Code()]) @@ -221,7 +224,7 @@ func sqliteConn(ctx context.Context, c *config.Config) (*DBConn, error) { tweakConnectionValues(sqldb) - if c.DBConfig.Address == "file::memory:?cache=shared" { + if dbAddress == "file::memory:?cache=shared" { logrus.Warn("sqlite in-memory database should only be used for debugging") // don't close connections on disconnect -- otherwise // the SQLite database will be deleted when there @@ -243,8 +246,8 @@ func sqliteConn(ctx context.Context, c *config.Config) (*DBConn, error) { return conn, nil } -func pgConn(ctx context.Context, c *config.Config) (*DBConn, error) { - opts, err := deriveBunDBPGOptions(c) +func pgConn(ctx context.Context) (*DBConn, error) { + opts, err := deriveBunDBPGOptions() if err != nil { return nil, fmt.Errorf("could not create bundb postgres options: %s", err) } @@ -270,54 +273,63 @@ func pgConn(ctx context.Context, c *config.Config) (*DBConn, error) { // deriveBunDBPGOptions takes an application config and returns either a ready-to-use set of options // with sensible defaults, or an error if it's not satisfied by the provided config. -func deriveBunDBPGOptions(c *config.Config) (*pgx.ConnConfig, error) { - if strings.ToUpper(c.DBConfig.Type) != db.DBTypePostgres { - return nil, fmt.Errorf("expected db type of %s but got %s", db.DBTypePostgres, c.DBConfig.Type) +func deriveBunDBPGOptions() (*pgx.ConnConfig, error) { + keys := config.Keys + + if strings.ToUpper(viper.GetString(keys.DbType)) != db.DBTypePostgres { + return nil, fmt.Errorf("expected db type of %s but got %s", db.DBTypePostgres, viper.GetString(keys.DbType)) } // validate port - if c.DBConfig.Port == 0 { + port := viper.GetInt(keys.DbPort) + if port == 0 { return nil, errors.New("no port set") } // validate address - if c.DBConfig.Address == "" { + address := viper.GetString(keys.DbAddress) + if address == "" { return nil, errors.New("no address set") } // validate username - if c.DBConfig.User == "" { + username := viper.GetString(keys.DbUser) + if username == "" { return nil, errors.New("no user set") } // validate that there's a password - if c.DBConfig.Password == "" { + password := viper.GetString(keys.DbPassword) + if password == "" { return nil, errors.New("no password set") } // validate database - if c.DBConfig.Database == "" { + database := viper.GetString(keys.DbDatabase) + if database == "" { return nil, errors.New("no database set") } var tlsConfig *tls.Config - switch c.DBConfig.TLSMode { - case config.DBTLSModeDisable, config.DBTLSModeUnset: + tlsMode := viper.GetString(keys.DbTLSMode) + switch tlsMode { + case dbTLSModeDisable, dbTLSModeUnset: break // nothing to do - case config.DBTLSModeEnable: + case dbTLSModeEnable: /* #nosec G402 */ tlsConfig = &tls.Config{ InsecureSkipVerify: true, } - case config.DBTLSModeRequire: + case dbTLSModeRequire: tlsConfig = &tls.Config{ InsecureSkipVerify: false, - ServerName: c.DBConfig.Address, + ServerName: viper.GetString(keys.DbAddress), MinVersion: tls.VersionTLS12, } } - if tlsConfig != nil && c.DBConfig.TLSCACert != "" { + caCertPath := viper.GetString(keys.DbTLSCACert) + if tlsConfig != nil && caCertPath != "" { // load the system cert pool first -- we'll append the given CA cert to this certPool, err := x509.SystemCertPool() if err != nil { @@ -325,24 +337,24 @@ func deriveBunDBPGOptions(c *config.Config) (*pgx.ConnConfig, error) { } // open the file itself and make sure there's something in it - caCertBytes, err := os.ReadFile(c.DBConfig.TLSCACert) + caCertBytes, err := os.ReadFile(caCertPath) if err != nil { - return nil, fmt.Errorf("error opening CA certificate at %s: %s", c.DBConfig.TLSCACert, err) + return nil, fmt.Errorf("error opening CA certificate at %s: %s", caCertPath, err) } if len(caCertBytes) == 0 { - return nil, fmt.Errorf("ca cert at %s was empty", c.DBConfig.TLSCACert) + return nil, fmt.Errorf("ca cert at %s was empty", caCertPath) } // make sure we have a PEM block caPem, _ := pem.Decode(caCertBytes) if caPem == nil { - return nil, fmt.Errorf("could not parse cert at %s into PEM", c.DBConfig.TLSCACert) + return nil, fmt.Errorf("could not parse cert at %s into PEM", caCertPath) } // parse the PEM block into the certificate caCert, err := x509.ParseCertificate(caPem.Bytes) if err != nil { - return nil, fmt.Errorf("could not parse cert at %s into x509 certificate: %s", c.DBConfig.TLSCACert, err) + return nil, fmt.Errorf("could not parse cert at %s into x509 certificate: %s", caCertPath, err) } // we're happy, add it to the existing pool and then use this pool in our tls config @@ -351,14 +363,14 @@ func deriveBunDBPGOptions(c *config.Config) (*pgx.ConnConfig, error) { } cfg, _ := pgx.ParseConfig("") - cfg.Host = c.DBConfig.Address - cfg.Port = uint16(c.DBConfig.Port) - cfg.User = c.DBConfig.User - cfg.Password = c.DBConfig.Password + cfg.Host = address + cfg.Port = uint16(port) + cfg.User = username + cfg.Password = password cfg.TLSConfig = tlsConfig - cfg.Database = c.DBConfig.Database + cfg.Database = database cfg.PreferSimpleProtocol = true - cfg.RuntimeParams["application_name"] = c.ApplicationName + cfg.RuntimeParams["application_name"] = viper.GetString(keys.ApplicationName) return cfg, nil } @@ -455,6 +467,9 @@ func (ps *bunDBService) MentionStringsToMentions(ctx context.Context, targetAcco } func (ps *bunDBService) TagStringsToTags(ctx context.Context, tags []string, originAccountID string) ([]*gtsmodel.Tag, error) { + protocol := viper.GetString(config.Keys.Protocol) + host := viper.GetString(config.Keys.Host) + newTags := []*gtsmodel.Tag{} for _, t := range tags { tag := >smodel.Tag{} @@ -468,7 +483,7 @@ func (ps *bunDBService) TagStringsToTags(ctx context.Context, tags []string, ori return nil, err } tag.ID = newID - tag.URL = fmt.Sprintf("%s://%s/tags/%s", ps.config.Protocol, ps.config.Host, t) + tag.URL = fmt.Sprintf("%s://%s/tags/%s", protocol, host, t) tag.Name = t tag.FirstSeenFromAccountID = originAccountID tag.CreatedAt = time.Now() diff --git a/internal/db/bundb/bundb_test.go b/internal/db/bundb/bundb_test.go index d4655a253..70fd58422 100644 --- a/internal/db/bundb/bundb_test.go +++ b/internal/db/bundb/bundb_test.go @@ -20,7 +20,6 @@ package bundb_test import ( "github.com/stretchr/testify/suite" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/testrig" @@ -29,8 +28,7 @@ import ( type BunDBStandardTestSuite struct { // standard suite interfaces suite.Suite - config *config.Config - db db.DB + db db.DB // standard suite models testTokens map[string]*gtsmodel.Token @@ -57,10 +55,10 @@ func (suite *BunDBStandardTestSuite) SetupSuite() { } func (suite *BunDBStandardTestSuite) SetupTest() { - suite.config = testrig.NewTestConfig() - suite.db = testrig.NewTestDB() testrig.InitTestLog() + testrig.InitTestConfig() + suite.db = testrig.NewTestDB() testrig.StandardDBSetup(suite.db, suite.testAccounts) } diff --git a/internal/db/bundb/domain.go b/internal/db/bundb/domain.go index 5cb98e87e..9e6aa968d 100644 --- a/internal/db/bundb/domain.go +++ b/internal/db/bundb/domain.go @@ -22,15 +22,13 @@ import ( "context" "net/url" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/util" ) type domainDB struct { - config *config.Config - conn *DBConn + conn *DBConn } func (d *domainDB) IsDomainBlocked(ctx context.Context, domain string) (bool, db.Error) { diff --git a/internal/db/bundb/instance.go b/internal/db/bundb/instance.go index 006a76e24..4c47a96f4 100644 --- a/internal/db/bundb/instance.go +++ b/internal/db/bundb/instance.go @@ -20,7 +20,9 @@ package bundb import ( "context" + "github.com/sirupsen/logrus" + "github.com/spf13/viper" "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" @@ -29,8 +31,7 @@ import ( ) type instanceDB struct { - config *config.Config - conn *DBConn + conn *DBConn } func (i *instanceDB) CountInstanceUsers(ctx context.Context, domain string) (int, db.Error) { @@ -40,7 +41,8 @@ func (i *instanceDB) CountInstanceUsers(ctx context.Context, domain string) (int Where("username != ?", domain). Where("? IS NULL", bun.Ident("suspended_at")) - if domain == i.config.Host { + host := viper.GetString(config.Keys.Host) + if domain == host { // if the domain is *this* domain, just count where the domain field is null q = q.WhereGroup(" AND ", whereEmptyOrNull("domain")) } else { @@ -59,7 +61,8 @@ func (i *instanceDB) CountInstanceStatuses(ctx context.Context, domain string) ( NewSelect(). Model(&[]*gtsmodel.Status{}) - if domain == i.config.Host { + host := viper.GetString(config.Keys.Host) + if domain == host { // if the domain is *this* domain, just count where local is true q = q.Where("local = ?", true) } else { @@ -80,7 +83,8 @@ func (i *instanceDB) CountInstanceDomains(ctx context.Context, domain string) (i NewSelect(). Model(&[]*gtsmodel.Instance{}) - if domain == i.config.Host { + host := viper.GetString(config.Keys.Host) + if domain == host { // if the domain is *this* domain, just count other instances it knows about // exclude domains that are blocked q = q. diff --git a/internal/db/bundb/media.go b/internal/db/bundb/media.go index 1a06a0260..5ea995a2d 100644 --- a/internal/db/bundb/media.go +++ b/internal/db/bundb/media.go @@ -21,15 +21,13 @@ package bundb import ( "context" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/uptrace/bun" ) type mediaDB struct { - config *config.Config - conn *DBConn + conn *DBConn } func (m *mediaDB) newMediaQ(i interface{}) *bun.SelectQuery { diff --git a/internal/db/bundb/mention.go b/internal/db/bundb/mention.go index 81ad216cc..f38b02a22 100644 --- a/internal/db/bundb/mention.go +++ b/internal/db/bundb/mention.go @@ -22,16 +22,14 @@ import ( "context" "github.com/ReneKroon/ttlcache" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/uptrace/bun" ) type mentionDB struct { - config *config.Config - conn *DBConn - cache *ttlcache.Cache + conn *DBConn + cache *ttlcache.Cache } func (m *mentionDB) newMentionQ(i interface{}) *bun.SelectQuery { diff --git a/internal/db/bundb/notification.go b/internal/db/bundb/notification.go index 212c97467..e9203c030 100644 --- a/internal/db/bundb/notification.go +++ b/internal/db/bundb/notification.go @@ -22,16 +22,14 @@ import ( "context" "github.com/ReneKroon/ttlcache" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/uptrace/bun" ) type notificationDB struct { - config *config.Config - conn *DBConn - cache *ttlcache.Cache + conn *DBConn + cache *ttlcache.Cache } func (n *notificationDB) newNotificationQ(i interface{}) *bun.SelectQuery { diff --git a/internal/db/bundb/relationship.go b/internal/db/bundb/relationship.go index a98a9f426..f8d1bccbe 100644 --- a/internal/db/bundb/relationship.go +++ b/internal/db/bundb/relationship.go @@ -23,15 +23,13 @@ import ( "database/sql" "fmt" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/uptrace/bun" ) type relationshipDB struct { - config *config.Config - conn *DBConn + conn *DBConn } func (r *relationshipDB) newBlockQ(block *gtsmodel.Block) *bun.SelectQuery { diff --git a/internal/db/bundb/session.go b/internal/db/bundb/session.go index acc70a868..60e582abd 100644 --- a/internal/db/bundb/session.go +++ b/internal/db/bundb/session.go @@ -23,15 +23,13 @@ import ( "crypto/rand" "errors" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/id" ) type sessionDB struct { - config *config.Config - conn *DBConn + conn *DBConn } func (s *sessionDB) GetSession(ctx context.Context) (*gtsmodel.RouterSession, db.Error) { diff --git a/internal/db/bundb/status.go b/internal/db/bundb/status.go index 73e2cb4c0..8c157e77a 100644 --- a/internal/db/bundb/status.go +++ b/internal/db/bundb/status.go @@ -25,16 +25,14 @@ import ( "github.com/sirupsen/logrus" "github.com/superseriousbusiness/gotosocial/internal/cache" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/uptrace/bun" ) type statusDB struct { - config *config.Config - conn *DBConn - cache *cache.StatusCache + conn *DBConn + cache *cache.StatusCache // TODO: keep method definitions in same place but instead have receiver // all point to one single "db" type, so they can all share methods diff --git a/internal/db/bundb/timeline.go b/internal/db/bundb/timeline.go index fb17fc53c..bb81d56cb 100644 --- a/internal/db/bundb/timeline.go +++ b/internal/db/bundb/timeline.go @@ -23,15 +23,13 @@ import ( "database/sql" "sort" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/uptrace/bun" ) type timelineDB struct { - config *config.Config - conn *DBConn + conn *DBConn } func (t *timelineDB) GetHomeTimeline(ctx context.Context, accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, db.Error) { |