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:
@@ -31,7 +31,7 @@ const crypto = require('crypto');
|
|||||||
let netkb = null; try { netkb = require('./netkb'); } catch (e) {}
|
let netkb = null; try { netkb = require('./netkb'); } catch (e) {}
|
||||||
|
|
||||||
let DATA_DIR = null, SEEDS = [], ready = null, SITE_URL = '', HELP_TEXT = '', MEMORY = false;
|
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
|
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)
|
// ---------------------------------------------------------------- text + scoring (pure, unit-tested)
|
||||||
@@ -196,9 +196,9 @@ function init(opts) {
|
|||||||
async function own() { await load(); return cache.slice(); }
|
async function own() { await load(); return cache.slice(); }
|
||||||
async function load(force) {
|
async function load(force) {
|
||||||
if (ready) await ready;
|
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();
|
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() : [];
|
index = buildIndex(cache.concat(netkb ? netkb.remote() : [])); index.sites = netkb ? netkb.sites() : [];
|
||||||
return cache;
|
return cache;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 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
|
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 };
|
||||||
|
|||||||
Reference in New Issue
Block a user