Site assistant: the knowledge index rebuilds as soon as the network set from the hub changes (was up to 30 s after boot, so the first cross-site questions missed the other sites)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-15 12:55:14 -06:00
parent 2b91ff5b8c
commit 131cf542ad
2 changed files with 5 additions and 4 deletions
+3 -3
View File
@@ -31,7 +31,7 @@ const crypto = require('crypto');
let netkb = null; try { netkb = require('./netkb'); } catch (e) {}
let DATA_DIR = null, SEEDS = [], ready = null, SITE_URL = '', HELP_TEXT = '', MEMORY = false;
let cache = null, cacheAt = 0, index = null;
let cache = null, cacheAt = 0, index = null, netVer = '';
const TTL = 30000; // two app copies share the volume for about 30 s during a deploy: re-read now and then
// ---------------------------------------------------------------- text + scoring (pure, unit-tested)
@@ -196,9 +196,9 @@ function init(opts) {
async function own() { await load(); return cache.slice(); }
async function load(force) {
if (ready) await ready;
if (!force && cache && Date.now() - cacheAt < TTL) return cache;
if (!force && cache && Date.now() - cacheAt < TTL && (!netkb || netkb.version() === netVer)) return cache; // a new network set rebuilds at once
const all = await store().all();
cache = all.filter(e => !e.deleted); cacheAt = Date.now(); rx.clear();
cache = all.filter(e => !e.deleted); cacheAt = Date.now(); rx.clear(); netVer = netkb ? netkb.version() : '';
index = buildIndex(cache.concat(netkb ? netkb.remote() : [])); index.sites = netkb ? netkb.sites() : [];
return cache;
}
+2 -1
View File
@@ -102,4 +102,5 @@ function init(opts) {
function view() { return Object.assign({ enabled: enabled(), site: siteName(), version: merged.version, sites: Object.keys(merged.sites || {}), entries: (merged.entries || []).length, remote: remote().length, loadedAt }, stats); }
function _set(m) { merged = m; } // tests
module.exports = { init, publish, publishSoon, refresh, remote, sites, view, enabled, _set };
const version = () => merged.version || '';
module.exports = { init, publish, publishSoon, refresh, remote, sites, view, enabled, version, _set };