Generate the changes for a specific list of doc ID's, only documents accessible to the user will generate results. Only supports non-continuous changes, closes buffered channel before returning.
(ctx context.Context, userChannels base.Set, explicitDocIds []string, options ChangesOptions)
| 1351 | // Generate the changes for a specific list of doc ID's, only documents accessible to the user will generate |
| 1352 | // results. Only supports non-continuous changes, closes buffered channel before returning. |
| 1353 | func (db *DatabaseCollectionWithUser) DocIDChangesFeed(ctx context.Context, userChannels base.Set, explicitDocIds []string, options ChangesOptions) (<-chan *ChangeEntry, error) { |
| 1354 | |
| 1355 | // Subroutine that creates a response row for a document: |
| 1356 | output := make(chan *ChangeEntry, len(explicitDocIds)) |
| 1357 | defer close(output) |
| 1358 | rowMap := make(map[uint64]*ChangeEntry) |
| 1359 | |
| 1360 | // Sort results by sequence |
| 1361 | var sequences base.SortedUint64Slice |
| 1362 | for _, docID := range explicitDocIds { |
| 1363 | row, err := createChangesEntry(ctx, docID, db, options) |
| 1364 | if err != nil { |
| 1365 | return nil, err |
| 1366 | } |
| 1367 | if row != nil { |
| 1368 | rowMap[row.Seq.Seq] = row |
| 1369 | sequences = append(sequences, row.Seq.Seq) |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | // Send ChangeEntries sorted by sequenceID |
| 1374 | sequences.Sort() |
| 1375 | for _, sequence := range sequences { |
| 1376 | output <- rowMap[sequence] |
| 1377 | if options.Limit > 0 { |
| 1378 | options.Limit-- |
| 1379 | if options.Limit == 0 { |
| 1380 | break |
| 1381 | } |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | return output, nil |
| 1386 | } |
| 1387 | |
| 1388 | // createChangesEntry is used when creating a doc ID filtered changes feed |
| 1389 | func createChangesEntry(ctx context.Context, docid string, db *DatabaseCollectionWithUser, options ChangesOptions) (*ChangeEntry, error) { |
no test coverage detected