@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/cli.cjs CHANGED
@@ -139010,22 +139010,36 @@ var StreamerServer = class {
139010
139010
  async handleConversationsCount(url2, res) {
139011
139011
  const project = url2.searchParams.get("project") ?? void 0;
139012
139012
  const bustCache = url2.searchParams.get("refresh") === "1";
139013
- if (bustCache) {
139014
- this.cache?.invalidate();
139015
- this.scanner = null;
139016
- this.scannerReady = null;
139017
- }
139018
- if (this.cache && !bustCache) {
139013
+ if (this.cache) {
139019
139014
  const { total } = this.cache.listConversations({ project, limit: 0, offset: 0 });
139020
139015
  json2(res, 200, { total });
139016
+ if (bustCache) this.refreshCountInBackground();
139021
139017
  return;
139022
139018
  }
139023
- const scanner = await this.getScanner();
139019
+ const scanner = await this.getScanner(true);
139024
139020
  let metas = [...scanner.getMetadataCache().values()];
139025
139021
  metas = applyIncludeFilter(metas, "conversations");
139026
139022
  if (project) metas = applyProjectFilter(metas, project);
139027
139023
  json2(res, 200, { total: metas.length });
139028
139024
  }
139025
+ // Fire-and-forget full rescan that reconciles the SQLite cache from disk so a
139026
+ // later count reflects new/removed conversations. Never awaited by the request
139027
+ // path — refresh=1 returns the cached total synchronously and this catches up.
139028
+ refreshCountInBackground() {
139029
+ void (async () => {
139030
+ try {
139031
+ const scanner = await this.getFreshScanner();
139032
+ if (this.cache) {
139033
+ this.cache.upsertFromScannerMeta([...scanner.getMetadataCache().values()]);
139034
+ }
139035
+ } catch (err) {
139036
+ this.log.warn(
139037
+ `Background count refresh failed: ${err instanceof Error ? err.message : String(err)}`,
139038
+ { event: "count.refresh_failed" }
139039
+ );
139040
+ }
139041
+ })();
139042
+ }
139029
139043
  handleSessionsCount(res) {
139030
139044
  json2(res, 200, { total: this.sessionStore.list(this.ptyAttachedIds()).length });
139031
139045
  }