(channels base.Set, options db.ChangesOptions, docids []string)
| 368 | } |
| 369 | |
| 370 | func (h *handler) sendSimpleChanges(channels base.Set, options db.ChangesOptions, docids []string) (error, bool) { |
| 371 | lastSeq := options.Since |
| 372 | var first bool = true |
| 373 | var feed <-chan *db.ChangeEntry |
| 374 | var err error |
| 375 | if len(docids) > 0 { |
| 376 | feed, err = h.collection.DocIDChangesFeed(h.ctx(), channels, docids, options) |
| 377 | } else { |
| 378 | feed, err = h.collection.MultiChangesFeed(h.ctx(), channels, options) |
| 379 | } |
| 380 | if err != nil { |
| 381 | return err, false |
| 382 | } |
| 383 | |
| 384 | h.setHeader("Content-Type", "application/json") |
| 385 | h.setHeader("Cache-Control", "private, max-age=0, no-cache, no-store") |
| 386 | _, _ = h.response.Write([]byte("{\"results\":[\r\n")) |
| 387 | |
| 388 | logStatus := h.logStatusWithDuration |
| 389 | |
| 390 | if options.Wait { |
| 391 | logStatus = h.logStatus |
| 392 | h.flush() |
| 393 | } |
| 394 | |
| 395 | message := "OK" |
| 396 | forceClose := false |
| 397 | if feed != nil { |
| 398 | var heartbeat, timeout <-chan time.Time |
| 399 | if options.Wait { |
| 400 | // Set up heartbeat/timeout |
| 401 | if options.HeartbeatMs > 0 { |
| 402 | ticker := time.NewTicker(time.Duration(options.HeartbeatMs) * time.Millisecond) |
| 403 | defer ticker.Stop() |
| 404 | heartbeat = ticker.C |
| 405 | } else if options.TimeoutMs > 0 { |
| 406 | timer := time.NewTimer(time.Duration(options.TimeoutMs) * time.Millisecond) |
| 407 | defer timer.Stop() |
| 408 | timeout = timer.C |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | encoder := base.JSONEncoderCanonical(h.response) |
| 413 | loop: |
| 414 | for { |
| 415 | select { |
| 416 | case entry, ok := <-feed: |
| 417 | if !ok { |
| 418 | break loop // end of feed |
| 419 | } |
| 420 | if nil != entry { |
| 421 | if entry.Err != nil { |
| 422 | break loop // error returned by feed - end changes |
| 423 | } |
| 424 | if first { |
| 425 | first = false |
| 426 | } else { |
| 427 | _, _ = h.response.Write([]byte(",")) |
no test coverage detected