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

Method GetUserNames

db/database.go:1082–1148  ·  view source on GitHub ↗

Returns the Names of all users

(ctx context.Context)

Source from the content-addressed store, hash-verified

1080
1081// Returns the Names of all users
1082func (db *DatabaseContext) GetUserNames(ctx context.Context) (users []string, err error) {
1083 dbUserPrefix := db.MetadataKeys.UserKeyPrefix()
1084 startKey := dbUserPrefix
1085 limit := db.Options.QueryPaginationLimit
1086 if limit == 0 {
1087 limit = DefaultQueryPaginationLimit
1088 }
1089
1090 userRe, err := regexp.Compile(`^` + dbUserPrefix + `[^:]*$`)
1091 if err != nil {
1092 return nil, err
1093 }
1094 users = []string{}
1095
1096outerLoop:
1097 for {
1098 results, err := db.QueryUsers(ctx, startKey, limit)
1099 if err != nil {
1100 return nil, err
1101 }
1102
1103 var principalName string
1104
1105 resultCount := 0
1106
1107 for {
1108 // startKey is inclusive for views, so need to skip first result if using non-empty startKey, as this results in an overlapping result
1109 var skipAddition bool
1110 if resultCount == 0 && startKey != dbUserPrefix {
1111 skipAddition = true
1112 }
1113
1114 var queryRow QueryUsersRow
1115 found := results.Next(ctx, &queryRow)
1116 if !found {
1117 break
1118 }
1119
1120 if !strings.HasPrefix(queryRow.ID, dbUserPrefix) {
1121 break
1122 }
1123
1124 principalName = queryRow.Name
1125 startKey = queryRow.ID
1126 resultCount++
1127
1128 if !userRe.MatchString(queryRow.ID) {
1129 continue
1130 }
1131
1132 if principalName != "" && !skipAddition {
1133 users = append(users, principalName)
1134 }
1135 }
1136
1137 closeErr := results.Close()
1138 if closeErr != nil {
1139 return nil, closeErr

Callers 2

AllPrincipalIDsMethod · 0.95
getUsersMethod · 0.80

Calls 4

QueryUsersMethod · 0.95
UserKeyPrefixMethod · 0.80
CloseMethod · 0.65
NextMethod · 0.45

Tested by

no test coverage detected