feat(dashboardapi): diff-skip regen via flows:started predicate (#36)
Subscribes to Node-RED's flows:started runtime event, caches the {diff}
payload on the dashboardAPI source, and short-circuits the child.register
handler when none of {dashboardAPI id, child id, grandchild ids} appears in
diff.added/changed/removed/rewired. Predicate verified by S1 spike (#32).
- src/nodeClass.js: _attachLifecycleHook subscribes, _attachCloseHandler
cleans up. No-op when RED.events isn't available (unit-test friendly).
- src/specificClass.js: subtreeChanged() predicate + subtreeIdsFor() helper.
- src/commands/handlers.js: registerChild consults predicate before composing;
logs {event:'regen-skipped', outcome:'no-diff'} when skipping.
- test/basic/slice36-diff-predicate.basic.test.js: 8 cases — null/empty diff,
affected/unaffected ids, tab-id over-triggering avoidance, grandchild
inclusion, no-grandchild case.
Cold start (no cached diff yet) always regenerates — safe default. Edge case
documented in #32: when a brand-new child is wired to a registered parent,
the new child's id is in diff.added but not yet in registeredChildren when
flows:started fires. Mitigation (b) per spike findings: one-deploy race
accepted for R&D — next deploy picks up the new registration.
Closes #36
This commit is contained in:
@@ -168,6 +168,34 @@ class DashboardApi {
|
||||
return out;
|
||||
}
|
||||
|
||||
// Predicate from Gitea issue #32 spike (S1 findings). Given the diff payload
|
||||
// from Node-RED's flows:started event and a set of node ids that constitute
|
||||
// "my subtree", decides whether the subtree changed on this deploy.
|
||||
// `null` diff (first deploy / startup) → always regen (safe default).
|
||||
subtreeChanged(diff, subtreeIds) {
|
||||
if (!diff) return true;
|
||||
const mine = new Set(subtreeIds);
|
||||
for (const field of ['added', 'changed', 'removed', 'rewired']) {
|
||||
const arr = diff[field] || [];
|
||||
if (arr.some((id) => mine.has(id))) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Collect ids that constitute "this dashboardAPI + this child + its grandchildren"
|
||||
// for the diff predicate. Pulls grandchildren via the existing extractChildren walk.
|
||||
subtreeIdsFor(dashboardApiNodeId, childSource) {
|
||||
const ids = new Set();
|
||||
if (dashboardApiNodeId) ids.add(dashboardApiNodeId);
|
||||
const childId = childSource?.config?.general?.id;
|
||||
if (childId) ids.add(childId);
|
||||
for (const { childSource: gc } of this.extractChildren(childSource)) {
|
||||
const gcId = gc?.config?.general?.id;
|
||||
if (gcId) ids.add(gcId);
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
generateDashboardsForGraph(rootSource, { includeChildren = true } = {}) {
|
||||
if (!rootSource?.config) {
|
||||
this.logger.warn('generateDashboardsForGraph skipped: root source missing config');
|
||||
|
||||
Reference in New Issue
Block a user