| 2047 | } |
| 2048 | |
| 2049 | func initDatabaseStats(ctx context.Context, dbName string, autoImport bool, options DatabaseContextOptions) (*base.DbStats, error) { |
| 2050 | |
| 2051 | enabledDeltaSync := options.DeltaSyncOptions.Enabled |
| 2052 | enabledImport := autoImport || options.EnableXattr |
| 2053 | enabledViews := options.UseViews |
| 2054 | |
| 2055 | var queryNames []string |
| 2056 | if enabledViews { |
| 2057 | queryNames = []string{ |
| 2058 | fmt.Sprintf(base.StatViewFormat, DesignDocSyncGateway(), ViewAccess), |
| 2059 | fmt.Sprintf(base.StatViewFormat, DesignDocSyncGateway(), ViewAccessVbSeq), |
| 2060 | fmt.Sprintf(base.StatViewFormat, DesignDocSyncGateway(), ViewChannels), |
| 2061 | fmt.Sprintf(base.StatViewFormat, DesignDocSyncGateway(), ViewPrincipals), |
| 2062 | fmt.Sprintf(base.StatViewFormat, DesignDocSyncGateway(), ViewRolesExcludeDeleted), |
| 2063 | fmt.Sprintf(base.StatViewFormat, DesignDocSyncGateway(), ViewRoleAccess), |
| 2064 | fmt.Sprintf(base.StatViewFormat, DesignDocSyncGateway(), ViewRoleAccessVbSeq), |
| 2065 | fmt.Sprintf(base.StatViewFormat, DesignDocSyncHousekeeping(), ViewAllDocs), |
| 2066 | fmt.Sprintf(base.StatViewFormat, DesignDocSyncHousekeeping(), ViewImport), |
| 2067 | fmt.Sprintf(base.StatViewFormat, DesignDocSyncHousekeeping(), ViewSessions), |
| 2068 | fmt.Sprintf(base.StatViewFormat, DesignDocSyncHousekeeping(), ViewTombstones), |
| 2069 | } |
| 2070 | } else { |
| 2071 | queryNames = []string{ |
| 2072 | QueryTypeAccess, |
| 2073 | QueryTypeRoleAccess, |
| 2074 | QueryTypeChannels, |
| 2075 | QueryTypeChannelsStar, |
| 2076 | QueryTypeSequences, |
| 2077 | QueryTypePrincipals, |
| 2078 | QueryTypeRolesExcludeDeleted, |
| 2079 | QueryTypeRoles, |
| 2080 | QueryTypeSessions, |
| 2081 | QueryTypeTombstones, |
| 2082 | QueryTypeResync, |
| 2083 | QueryTypeAllDocs, |
| 2084 | QueryTypeUsers, |
| 2085 | } |
| 2086 | } |
| 2087 | |
| 2088 | if options.UserFunctions != nil { |
| 2089 | for _, fn := range options.UserFunctions.Definitions { |
| 2090 | if queryName, ok := fn.N1QLQueryName(); ok { |
| 2091 | queryNames = append(queryNames, queryName) |
| 2092 | } |
| 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | var collections []string |
| 2097 | if len(options.Scopes) == 0 { |
| 2098 | base.DebugfCtx(ctx, base.KeyAll, "No named collections defined for database %q, using default collection for stats", base.MD(dbName)) |
| 2099 | collections = append(collections, base.DefaultScope+"."+base.DefaultCollection) |
| 2100 | } else { |
| 2101 | for scopeName, scope := range options.Scopes { |
| 2102 | for collectionName := range scope.Collections { |
| 2103 | collections = append(collections, scopeName+"."+collectionName) |
| 2104 | } |
| 2105 | } |
| 2106 | } |