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

Function removeObsoleteDesignDocs

db/design_doc.go:713–757  ·  view source on GitHub ↗
(ctx context.Context, viewStore sgbucket.ViewStore, previewOnly bool, useViews bool)

Source from the content-addressed store, hash-verified

711}
712
713func removeObsoleteDesignDocs(ctx context.Context, viewStore sgbucket.ViewStore, previewOnly bool, useViews bool) (removedDesignDocs []string, err error) {
714
715 removedDesignDocs = make([]string, 0)
716 designDocPrefixes := []string{DesignDocSyncGatewayPrefix, DesignDocSyncHousekeepingPrefix}
717
718 versionsToRemove := DesignDocPreviousVersions
719
720 if !useViews {
721 versionsToRemove = append(versionsToRemove, DesignDocVersion)
722 }
723
724 for _, previousVersion := range versionsToRemove {
725 for _, ddocPrefix := range designDocPrefixes {
726 var ddocName string
727 if previousVersion == "" {
728 ddocName = ddocPrefix
729 } else {
730 ddocName = fmt.Sprintf(DesignDocFormat, ddocPrefix, previousVersion)
731 }
732
733 if !previewOnly {
734 removeDDocErr := viewStore.DeleteDDoc(ddocName)
735 if removeDDocErr != nil && !IsMissingDDocError(removeDDocErr) {
736 base.WarnfCtx(ctx, "Unexpected error when removing design doc %q: %s", ddocName, removeDDocErr)
737 }
738 // Only include in list of removedDesignDocs if it was actually removed
739 if removeDDocErr == nil {
740 removedDesignDocs = append(removedDesignDocs, ddocName)
741 }
742 } else {
743 _, existsDDocErr := viewStore.GetDDoc(ddocName)
744 if existsDDocErr != nil && !IsMissingDDocError(existsDDocErr) {
745 base.WarnfCtx(ctx, "Unexpected error when checking existence of design doc %q: %s", ddocName, existsDDocErr)
746 }
747 // Only include in list of removedDesignDocs if it exists
748 if existsDDocErr == nil {
749 removedDesignDocs = append(removedDesignDocs, ddocName)
750 }
751
752 }
753 }
754
755 }
756 return removedDesignDocs, nil
757}
758
759// Similar to IsDocNotFoundError(), but for the specific error returned by GetDDoc/DeleteDDoc
760func IsMissingDDocError(err error) bool {

Calls 4

WarnfCtxFunction · 0.92
IsMissingDDocErrorFunction · 0.85
DeleteDDocMethod · 0.45
GetDDocMethod · 0.45