@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.d.cts CHANGED
@@ -752,6 +752,7 @@ declare class StreamerServer {
752
752
  private checkExchangeRateLimit;
753
753
  private handleListConversations;
754
754
  private handleConversationsCount;
755
+ private refreshCountInBackground;
755
756
  private handleSessionsCount;
756
757
  private handleGetRecentSessions;
757
758
  private handleGetPopularProjects;
package/dist/index.d.ts CHANGED
@@ -752,6 +752,7 @@ declare class StreamerServer {
752
752
  private checkExchangeRateLimit;
753
753
  private handleListConversations;
754
754
  private handleConversationsCount;
755
+ private refreshCountInBackground;
755
756
  private handleSessionsCount;
756
757
  private handleGetRecentSessions;
757
758
  private handleGetPopularProjects;
package/dist/index.js CHANGED
@@ -4606,22 +4606,36 @@ var StreamerServer = class {
4606
4606
  async handleConversationsCount(url, res) {
4607
4607
  const project = url.searchParams.get("project") ?? void 0;
4608
4608
  const bustCache = url.searchParams.get("refresh") === "1";
4609
- if (bustCache) {
4610
- this.cache?.invalidate();
4611
- this.scanner = null;
4612
- this.scannerReady = null;
4613
- }
4614
- if (this.cache && !bustCache) {
4609
+ if (this.cache) {
4615
4610
  const { total } = this.cache.listConversations({ project, limit: 0, offset: 0 });
4616
4611
  json(res, 200, { total });
4612
+ if (bustCache) this.refreshCountInBackground();
4617
4613
  return;
4618
4614
  }
4619
- const scanner = await this.getScanner();
4615
+ const scanner = await this.getScanner(true);
4620
4616
  let metas = [...scanner.getMetadataCache().values()];
4621
4617
  metas = applyIncludeFilter(metas, "conversations");
4622
4618
  if (project) metas = applyProjectFilter(metas, project);
4623
4619
  json(res, 200, { total: metas.length });
4624
4620
  }
4621
+ // Fire-and-forget full rescan that reconciles the SQLite cache from disk so a
4622
+ // later count reflects new/removed conversations. Never awaited by the request
4623
+ // path — refresh=1 returns the cached total synchronously and this catches up.
4624
+ refreshCountInBackground() {
4625
+ void (async () => {
4626
+ try {
4627
+ const scanner = await this.getFreshScanner();
4628
+ if (this.cache) {
4629
+ this.cache.upsertFromScannerMeta([...scanner.getMetadataCache().values()]);
4630
+ }
4631
+ } catch (err) {
4632
+ this.log.warn(
4633
+ `Background count refresh failed: ${err instanceof Error ? err.message : String(err)}`,
4634
+ { event: "count.refresh_failed" }
4635
+ );
4636
+ }
4637
+ })();
4638
+ }
4625
4639
  handleSessionsCount(res) {
4626
4640
  json(res, 200, { total: this.sessionStore.list(this.ptyAttachedIds()).length });
4627
4641
  }