MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / InitializeViews

Function InitializeViews

db/design_doc.go:352–376  ·  view source on GitHub ↗
(ctx context.Context, ds sgbucket.DataStore)

Source from the content-addressed store, hash-verified

350}
351
352func InitializeViews(ctx context.Context, ds sgbucket.DataStore) error {
353 collection, isCBServerCollection := ds.(*base.Collection)
354 if isCBServerCollection && !collection.IsDefaultScopeCollection() {
355 return fmt.Errorf("Can not initialize views on a non-default Couchbase Server collection")
356 }
357
358 viewStore, ok := ds.(sgbucket.ViewStore)
359 if !ok {
360 return fmt.Errorf("Datastore does not support views")
361 }
362
363 // Check whether design docs are already present
364 ddocsExist := checkExistingDDocs(ctx, viewStore)
365
366 // If not present, install design docs and views
367 if !ddocsExist {
368 base.InfofCtx(ctx, base.KeyAll, "Design docs for current view version (%s) do not exist - creating...", DesignDocVersion)
369 if err := installViews(ctx, viewStore); err != nil {
370 return err
371 }
372 }
373
374 // Wait for views to be indexed and available
375 return WaitForViews(ctx, ds)
376}
377
378func checkExistingDDocs(ctx context.Context, viewStore sgbucket.ViewStore) bool {
379

Callers 3

viewBucketReadierFunction · 0.85

Calls 6

InfofCtxFunction · 0.92
checkExistingDDocsFunction · 0.85
installViewsFunction · 0.85
WaitForViewsFunction · 0.85
ErrorfMethod · 0.80

Tested by 1