One query. An unmoved revision is not an event.
()
| 422 | |
| 423 | /** One query. An unmoved revision is not an event. */ |
| 424 | private checkIndex(): void { |
| 425 | if (this.closed || this.clients.size === 0) return; |
| 426 | const next = this.probe(); |
| 427 | if (next === null) return; |
| 428 | const previous = this.revision; |
| 429 | this.revision = next; |
| 430 | if ( |
| 431 | previous !== null && |
| 432 | previous.lastIndexedAt === next.lastIndexedAt && |
| 433 | previous.files === next.files |
| 434 | ) { |
| 435 | return; |
| 436 | } |
| 437 | |
| 438 | // Everything re-indexed since the mark we were holding. A sync that only |
| 439 | // removed files names nothing here — which is why the revision comparison |
| 440 | // above, not this list, decides whether an event happens at all. |
| 441 | let files: string[] = []; |
| 442 | let total = 0; |
| 443 | const since = previous?.lastIndexedAt ?? null; |
| 444 | if (since !== null) { |
| 445 | try { |
| 446 | const changed = this.session.acquire().getFilesIndexedSince(since, MAX_EVENT_FILES); |
| 447 | files = changed.paths; |
| 448 | total = changed.total; |
| 449 | } catch { |
| 450 | /* the index went away between the probe and here — the event still stands */ |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | this.broadcast({ |
| 455 | type: 'index', |
| 456 | index: next, |
| 457 | files, |
| 458 | total: Math.max(total, files.length), |
| 459 | truncated: files.length < total, |
| 460 | at: Date.now(), |
| 461 | }); |
| 462 | } |
| 463 | |
| 464 | /** |
| 465 | * The current revision, or null when there is no readable index. |
no test coverage detected