Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure index is used when running on MySQL #1639

Merged
merged 4 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't pass gorm DB struct by value
The latest version of gorm adds a RWMutex to this struct so we can't
pass by value or we will copy the mutex.

Signed-off-by: Jonny Stoten <[email protected]>
  • Loading branch information
jonnystoten committed May 12, 2022
commit e9fca7516c1d64465d4fdd3b8cb83d891efee9f0
2 changes: 1 addition & 1 deletion server/storage/concurrent_sqldb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func init() {
gormDB.Close()
dbStore := SetupSQLDB(t, backend, dburl)
return dbStore, func() {
dropTables(&dbStore.DB)
dropTables(dbStore.DB)
dbStore.Close()
}
}
Expand Down
4 changes: 2 additions & 2 deletions server/storage/sql_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c SQLChange) TableName() string {
}

// CreateTUFTable creates the DB table for TUFFile
func CreateTUFTable(db gorm.DB) error {
func CreateTUFTable(db *gorm.DB) error {
// TODO: gorm
query := db.AutoMigrate(&TUFFile{})
if query.Error != nil {
Expand All @@ -60,7 +60,7 @@ func CreateTUFTable(db gorm.DB) error {
}

// CreateChangefeedTable creates the DB table for Changefeed
func CreateChangefeedTable(db gorm.DB) error {
func CreateChangefeedTable(db *gorm.DB) error {
query := db.AutoMigrate(&SQLChange{})
return query.Error
}
6 changes: 3 additions & 3 deletions server/storage/sqldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// SQLStorage implements a versioned store using a relational database.
// See server/storage/models.go
type SQLStorage struct {
gorm.DB
*gorm.DB
}

// NewSQLStorage is a convenience method to create a SQLStorage
Expand All @@ -28,7 +28,7 @@ func NewSQLStorage(dialect string, args ...interface{}) (*SQLStorage, error) {
return nil, err
}
return &SQLStorage{
DB: *gormDB,
DB: gormDB,
}, nil
}

Expand Down Expand Up @@ -311,7 +311,7 @@ func (db *SQLStorage) CheckHealth() error {
func (db *SQLStorage) GetChanges(changeID string, records int, filterName string) ([]Change, error) {
var (
changes []Change
query = &db.DB
query = db.DB
id int64
err error
)
Expand Down
2 changes: 1 addition & 1 deletion server/storage/sqldb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type sqldbSetupFunc func(*testing.T) (*SQLStorage, func())

var sqldbSetup sqldbSetupFunc

func assertExpectedGormTUFMeta(t *testing.T, expected []StoredTUFMeta, gormDB gorm.DB) {
func assertExpectedGormTUFMeta(t *testing.T, expected []StoredTUFMeta, gormDB *gorm.DB) {
expectedGorm := make([]TUFFile, len(expected))
for i, tufObj := range expected {
expectedGorm[i] = TUFFile{
Expand Down