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

CBG3026 prereq: More low-risk cleanup/refactoring #7120

Merged
merged 2 commits into from
Sep 20, 2024
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
6 changes: 3 additions & 3 deletions db/design_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ func stripSyncProperty(row *sgbucket.ViewRow) {
}

func InitializeViews(ctx context.Context, ds sgbucket.DataStore) error {
collection, ok := ds.(*base.Collection)
if ok && !collection.IsDefaultScopeCollection() {
return fmt.Errorf("Can not initialize views on a non default collection")
collection, isCBServerCollection := ds.(*base.Collection)
if isCBServerCollection && !collection.IsDefaultScopeCollection() {
return fmt.Errorf("Can not initialize views on a non-default Couchbase Server collection")
}

viewStore, ok := ds.(sgbucket.ViewStore)
Expand Down
1 change: 1 addition & 0 deletions db/indexes.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ func InitializeIndexes(ctx context.Context, n1QLStore base.N1QLStore, options In
deferredIndexes := make([]string, 0)
for _, sgIndex := range sgIndexes {

// TODO CBG-2838: build list of indexes to create (with one GetIndexMeta call)
if !sgIndex.shouldCreate(options) {
base.DebugfCtx(ctx, base.KeyAll, "Skipping index: %s ...", sgIndex.simpleName)
continue
Expand Down
4 changes: 2 additions & 2 deletions rest/indextest/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestSyncGatewayStartupIndexes(t *testing.T) {
}

// tests sg_users index
t.Run("testUserQueries", func(t *testing.T) {
rt.Run("testUserQueries", func(t *testing.T) {
users := []string{"alice", "bob"}

for _, user := range users {
Expand All @@ -96,7 +96,7 @@ func TestSyncGatewayStartupIndexes(t *testing.T) {
})

// tests sg_roles index
t.Run("testRoleQueries", func(t *testing.T) {
rt.Run("testRoleQueries", func(t *testing.T) {
roles := []string{"roleA", "roleB"}

for _, role := range roles {
Expand Down
16 changes: 8 additions & 8 deletions rest/server_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,14 @@ func (sc *ServerContext) _getOrAddDatabaseFromConfig(ctx context.Context, config
dbName = spec.BucketName
}

// Generate database context options from config and server context
contextOptions, err := dbcOptionsFromConfig(ctx, sc, &config.DbConfig, dbName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check that this is okay that this isn't going to return an error for db.ValidateDatabaseName?

Copy link
Member Author

@bbrks bbrks Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I missed that. I also realised this code is being put before the defer as well, so I'll move things down a bit. There's also the duplicate check we probably want to do first to exit early.

if err != nil {
return nil, err
}
// set this early so we have dbName available in db-init related logging, before we have an actual database
ctx = base.DatabaseLogCtx(ctx, dbName, contextOptions.LoggingConfig)

defer func() {
if returnedError == nil {
return
Expand Down Expand Up @@ -777,14 +785,6 @@ func (sc *ServerContext) _getOrAddDatabaseFromConfig(ctx context.Context, config
return nil, err
}

// Generate database context options from config and server context
contextOptions, err := dbcOptionsFromConfig(ctx, sc, &config.DbConfig, dbName)
if err != nil {
return nil, err
}

ctx = base.DatabaseLogCtx(ctx, dbName, contextOptions.LoggingConfig)

contextOptions.UseViews = useViews

javascriptTimeout := getJavascriptTimeout(&config.DbConfig)
Expand Down
Loading