@threadbase-sh/streamer 1.16.0 → 1.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -4640,22 +4640,36 @@ var StreamerServer = class {
4640
4640
  async handleConversationsCount(url, res) {
4641
4641
  const project = url.searchParams.get("project") ?? void 0;
4642
4642
  const bustCache = url.searchParams.get("refresh") === "1";
4643
- if (bustCache) {
4644
- this.cache?.invalidate();
4645
- this.scanner = null;
4646
- this.scannerReady = null;
4647
- }
4648
- if (this.cache && !bustCache) {
4643
+ if (this.cache) {
4649
4644
  const { total } = this.cache.listConversations({ project, limit: 0, offset: 0 });
4650
4645
  json(res, 200, { total });
4646
+ if (bustCache) this.refreshCountInBackground();
4651
4647
  return;
4652
4648
  }
4653
- const scanner = await this.getScanner();
4649
+ const scanner = await this.getScanner(true);
4654
4650
  let metas = [...scanner.getMetadataCache().values()];
4655
4651
  metas = (0, import_scanner2.applyIncludeFilter)(metas, "conversations");
4656
4652
  if (project) metas = (0, import_scanner2.applyProjectFilter)(metas, project);
4657
4653
  json(res, 200, { total: metas.length });
4658
4654
  }
4655
+ // Fire-and-forget full rescan that reconciles the SQLite cache from disk so a
4656
+ // later count reflects new/removed conversations. Never awaited by the request
4657
+ // path — refresh=1 returns the cached total synchronously and this catches up.
4658
+ refreshCountInBackground() {
4659
+ void (async () => {
4660
+ try {
4661
+ const scanner = await this.getFreshScanner();
4662
+ if (this.cache) {
4663
+ this.cache.upsertFromScannerMeta([...scanner.getMetadataCache().values()]);
4664
+ }
4665
+ } catch (err) {
4666
+ this.log.warn(
4667
+ `Background count refresh failed: ${err instanceof Error ? err.message : String(err)}`,
4668
+ { event: "count.refresh_failed" }
4669
+ );
4670
+ }
4671
+ })();
4672
+ }
4659
4673
  handleSessionsCount(res) {
4660
4674
  json(res, 200, { total: this.sessionStore.list(this.ptyAttachedIds()).length });
4661
4675
  }