Iterate over the results of an AllDocs query, performing ForEachDocID handling for each row
(ctx context.Context, callback ForEachDocIDFunc, limit uint64, results sgbucket.QueryResultIterator)
| 994 | |
| 995 | // Iterate over the results of an AllDocs query, performing ForEachDocID handling for each row |
| 996 | func (c *DatabaseCollection) processForEachDocIDResults(ctx context.Context, callback ForEachDocIDFunc, limit uint64, results sgbucket.QueryResultIterator) error { |
| 997 | |
| 998 | count := uint64(0) |
| 999 | for { |
| 1000 | var queryRow AllDocsIndexQueryRow |
| 1001 | var found bool |
| 1002 | var docid, revid string |
| 1003 | var seq uint64 |
| 1004 | var cv string |
| 1005 | var channels []string |
| 1006 | if c.useViews() { |
| 1007 | var viewRow AllDocsViewQueryRow |
| 1008 | found = results.Next(ctx, &viewRow) |
| 1009 | if found { |
| 1010 | docid = viewRow.Key |
| 1011 | revid = viewRow.Value.Rev.RevTreeID |
| 1012 | cv = viewRow.Value.Rev.CV() |
| 1013 | seq = viewRow.Value.Sequence |
| 1014 | channels = viewRow.Value.Channels |
| 1015 | } |
| 1016 | } else { |
| 1017 | found = results.Next(ctx, &queryRow) |
| 1018 | if found { |
| 1019 | docid = queryRow.Id |
| 1020 | revid = queryRow.Rev.RevTreeID |
| 1021 | cv = queryRow.Rev.CV() |
| 1022 | seq = queryRow.Sequence |
| 1023 | channels = make([]string, 0) |
| 1024 | // Query returns all channels, but we only want to return active channels |
| 1025 | for channelName, removal := range queryRow.Channels { |
| 1026 | if removal == nil { |
| 1027 | channels = append(channels, channelName) |
| 1028 | } |
| 1029 | } |
| 1030 | } |
| 1031 | } |
| 1032 | if !found { |
| 1033 | break |
| 1034 | } |
| 1035 | |
| 1036 | if ok, err := callback(IDRevAndSequence{DocID: docid, RevID: revid, Sequence: seq, CV: cv}, channels); ok { |
| 1037 | count++ |
| 1038 | } else if err != nil { |
| 1039 | return err |
| 1040 | } |
| 1041 | // We have to apply limit check after callback has been called |
| 1042 | // to account for rows that are not in the current users channels |
| 1043 | if limit > 0 && count == limit { |
| 1044 | break |
| 1045 | } |
| 1046 | |
| 1047 | } |
| 1048 | return nil |
| 1049 | } |
| 1050 | |
| 1051 | // Returns the IDs of all users and roles, including deleted Roles |
| 1052 | func (db *DatabaseContext) AllPrincipalIDs(ctx context.Context) (users, roles []string, err error) { |
no test coverage detected