Reload only the rows that changed
Refreshing rebuilt the whole tree, and TreeView.reload() with no argument drops the scroll position. Watching a job meant the view jumped every fifteen seconds. The provider now reconciles instead of replacing. update() rebuilds from the store, matches rows to the existing nodes by identifier, copies the rendered fields onto them, and reports the topmost rows that actually changed; main.js reloads just those. Node identity survives the merge, which is what makes a targeted reload possible. An open row that fetches its own children has that cache dropped so it refetches — the running-job path. A job finishing now reloads one run's row and nothing else. Sections also each describe what they draw, so a section only rebuilds when its own content moved: run activity no longer disturbs the pull request list, and an idle tree is left alone entirely. This does not slow anything down — a section showing a run in progress still updates on every poll, and contributes a time bucket so its elapsed clock keeps moving. A row set changing at the root still needs a whole-tree reload; there the selected row is re-revealed afterwards, which is the closest thing to a scroll anchor Nova exposes. Adds seventeen checks: no-op updates reporting nothing, a finishing job naming only its own row, node identity surviving, a new run reloading just its workflow group, and a new workflow escalating to a full reload. 168 checks total. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MQuusXgZC2dzwpJJ1qhtti
This commit is contained in:
+66
-17
@@ -59,11 +59,60 @@ function buildSections(store) {
|
||||
});
|
||||
}
|
||||
|
||||
/** Rebuilds every section from current store state. */
|
||||
function reloadSections(sections) {
|
||||
for (const section of sections) {
|
||||
section.provider.invalidate();
|
||||
section.view.reload().catch((error) => log.debug("reload failed", String(error)));
|
||||
/**
|
||||
* Applies a section's changes to the view. Only the rows that actually changed
|
||||
* are reloaded, which is what keeps the scroll position while a job is being
|
||||
* watched. A shape change that cannot be patched falls back to a full reload,
|
||||
* and there the selected row is used to put the view back roughly where it was
|
||||
* — Nova exposes no way to read or set a tree's scroll offset directly.
|
||||
*/
|
||||
async function reloadSection(section) {
|
||||
let update;
|
||||
try {
|
||||
update = await section.provider.update();
|
||||
} catch (error) {
|
||||
log.debug("could not rebuild the section", String(error));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!update) return;
|
||||
|
||||
if (!update.full) {
|
||||
for (const node of update.nodes) {
|
||||
try {
|
||||
await section.view.reload(node);
|
||||
} catch (error) {
|
||||
// Nova may not know this row; redraw everything instead.
|
||||
log.debug("row reload failed, falling back to a full reload", String(error));
|
||||
await fullReload(section);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
await fullReload(section);
|
||||
}
|
||||
|
||||
async function fullReload(section) {
|
||||
const anchor = (section.view.selection || [])[0];
|
||||
const identifier = anchor ? anchor.identifier : null;
|
||||
|
||||
try {
|
||||
await section.view.reload();
|
||||
} catch (error) {
|
||||
log.debug("reload failed", String(error));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!identifier) return;
|
||||
|
||||
try {
|
||||
const restored = await section.provider.findByIdentifier(identifier);
|
||||
if (restored) await section.view.reveal(restored, { select: true, focus: false });
|
||||
} catch (error) {
|
||||
// The row may simply be gone now; losing the anchor is not an error.
|
||||
log.debug("could not restore the selection", String(error));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,11 +202,12 @@ exports.activate = function () {
|
||||
);
|
||||
|
||||
let timer = null;
|
||||
let lastSignature = null;
|
||||
const signatures = new Map();
|
||||
|
||||
/** Drops the memo so the next change redraws unconditionally. */
|
||||
/** Forces the next change to rebuild every section from scratch. */
|
||||
const redraw = () => {
|
||||
lastSignature = null;
|
||||
signatures.clear();
|
||||
for (const section of sections) section.provider.invalidate();
|
||||
};
|
||||
|
||||
const scheduleReload = () => {
|
||||
@@ -165,16 +215,15 @@ exports.activate = function () {
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
|
||||
// Reloading rebuilds every row, which is disruptive even with
|
||||
// expansion preserved, so a poll that changed nothing does nothing.
|
||||
const signature = store.signature();
|
||||
if (signature === lastSignature) {
|
||||
log.debug("nothing changed; leaving the sidebar alone");
|
||||
return;
|
||||
}
|
||||
lastSignature = signature;
|
||||
// Each section decides for itself. Run activity must not redraw the
|
||||
// pull request list, and an idle poll must redraw nothing at all.
|
||||
for (const section of sections) {
|
||||
const signature = section.provider.signature();
|
||||
if (signature !== null && signature === signatures.get(section.id)) continue;
|
||||
|
||||
reloadSections(sections);
|
||||
signatures.set(section.id, signature);
|
||||
reloadSection(section);
|
||||
}
|
||||
}, RELOAD_DEBOUNCE_MS);
|
||||
};
|
||||
|
||||
|
||||
+64
-62
@@ -328,73 +328,75 @@ class Store {
|
||||
this.notify();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fingerprint of everything the sidebar draws. `main.js` compares it before
|
||||
* reloading, so an idle poll that changes nothing leaves the tree — and the
|
||||
* user's scroll position and open rows — completely alone.
|
||||
*/
|
||||
signature() {
|
||||
const parts = [];
|
||||
// -- Change detection --------------------------------------------------
|
||||
//
|
||||
// Sections compose these into their own signature. Reloading rebuilds every
|
||||
// row and loses the scroll position, so a section redraws only when what it
|
||||
// actually shows has changed — run churn must not disturb someone reading
|
||||
// pull requests, and nothing at all should disturb an idle tree.
|
||||
|
||||
// The loading flag only reaches the screen while there is nothing else
|
||||
// to show; including it always would defeat the whole comparison.
|
||||
/** Whether there is anything to draw, and which repositories. */
|
||||
baseSignature() {
|
||||
const parts = [
|
||||
`error:${this.lastError || ""}`,
|
||||
`unmatched:${this.unmatchedHosts.map((entry) => entry.host).join(",")}`,
|
||||
`repos:${this.repos.map((repo) => `${repo.key}/${repo.branch || ""}`).join(",")}`,
|
||||
];
|
||||
// Only reaches the screen while there is nothing else to show.
|
||||
if (!this.repos.length) parts.push(`loading:${this.loading}`);
|
||||
parts.push(`error:${this.lastError || ""}`);
|
||||
|
||||
for (const entry of this.unmatchedHosts) parts.push(`unmatched:${entry.host}`);
|
||||
|
||||
// The branch filter changes what is drawn without changing any data.
|
||||
const filter = config.branchFilter();
|
||||
parts.push(`filter:${filter.mode}:${filter.branch || ""}`);
|
||||
|
||||
for (const [baseUrl, status] of this.instanceStatus) {
|
||||
parts.push(
|
||||
`instance:${baseUrl}:${status.ok}:${status.version || ""}:${status.user || ""}:${status.error || ""}`,
|
||||
);
|
||||
}
|
||||
|
||||
for (const repo of this.repos) {
|
||||
parts.push(`repo:${repo.key}:${repo.branch || ""}`);
|
||||
|
||||
const runs = this.runsFor(repo.key);
|
||||
parts.push(`runs:${runs.error || ""}:${runs.legacy}`);
|
||||
for (const run of runs.runs) {
|
||||
parts.push(`run:${run.id}:${run.status}:${run.conclusion}:${run.updated_at || ""}`);
|
||||
}
|
||||
|
||||
const pulls = this.pullRequestsFor(repo.key);
|
||||
parts.push(`pulls:${pulls.error || ""}`);
|
||||
for (const pull of pulls.items) {
|
||||
parts.push(`pull:${pull.number}:${pull.state}:${pull.draft}:${pull.updated_at}`);
|
||||
}
|
||||
|
||||
const secrets = this.secrets.get(repo.key);
|
||||
if (secrets) {
|
||||
parts.push(
|
||||
`secrets:${secrets.error || ""}:${secrets.items.map((x) => x.name).join(",")}`,
|
||||
);
|
||||
}
|
||||
|
||||
const variables = this.variables.get(repo.key);
|
||||
if (variables) {
|
||||
parts.push(
|
||||
`variables:${variables.error || ""}:${variables.items
|
||||
.map((x) => `${x.name}=${x.data || x.value || ""}`)
|
||||
.join(",")}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// While something is running its elapsed time is on screen and has to
|
||||
// keep moving, so let the signature change once per active interval.
|
||||
if (this.hasActiveRuns) {
|
||||
const seconds = Math.max(5, config.runningInterval());
|
||||
parts.push(`tick:${Math.floor(Date.now() / 1000 / seconds)}`);
|
||||
}
|
||||
|
||||
return parts.join("|");
|
||||
}
|
||||
|
||||
runsSignature(repoKey) {
|
||||
const entry = this.runsFor(repoKey);
|
||||
return [
|
||||
`runs:${entry.error || ""}/${entry.legacy}`,
|
||||
...entry.runs.map(
|
||||
(run) => `${run.id}/${run.status}/${run.conclusion}/${run.updated_at || ""}`,
|
||||
),
|
||||
].join(",");
|
||||
}
|
||||
|
||||
pullsSignature(repoKey) {
|
||||
const entry = this.pullRequestsFor(repoKey);
|
||||
return [
|
||||
`pulls:${entry.error || ""}`,
|
||||
...entry.items.map(
|
||||
(pull) => `${pull.number}/${pull.state}/${pull.draft}/${pull.updated_at}`,
|
||||
),
|
||||
].join(",");
|
||||
}
|
||||
|
||||
instancesSignature() {
|
||||
return [...this.instanceStatus.entries()]
|
||||
.map(([url, s]) => `${url}/${s.ok}/${s.version || ""}/${s.user || ""}/${s.error || ""}`)
|
||||
.join(",");
|
||||
}
|
||||
|
||||
settingsSignature(repoKey) {
|
||||
const secrets = this.secrets.get(repoKey);
|
||||
const variables = this.variables.get(repoKey);
|
||||
return [
|
||||
secrets ? `s:${secrets.error || ""}/${secrets.items.map((x) => x.name).join(",")}` : "s:-",
|
||||
variables
|
||||
? `v:${variables.error || ""}/${variables.items
|
||||
.map((x) => `${x.name}=${x.data || x.value || ""}`)
|
||||
.join(",")}`
|
||||
: "v:-",
|
||||
].join("|");
|
||||
}
|
||||
|
||||
/**
|
||||
* A coarse time bucket, present only while one of `runs` is in progress, so
|
||||
* a section showing a live elapsed clock keeps it moving — and a section
|
||||
* showing none of them stays perfectly still.
|
||||
*/
|
||||
elapsedTick(runs) {
|
||||
if (!runs.some(isActiveRun)) return "";
|
||||
const seconds = Math.max(5, config.runningInterval());
|
||||
return `tick:${Math.floor(Date.now() / 1000 / seconds)}`;
|
||||
}
|
||||
|
||||
// -- Housekeeping ------------------------------------------------------
|
||||
|
||||
_pruneCaches() {
|
||||
|
||||
@@ -11,6 +11,18 @@ const { NodeProvider } = require("./provider.js");
|
||||
const { node, message, errorNode } = nodes;
|
||||
|
||||
class BranchProvider extends NodeProvider {
|
||||
signature() {
|
||||
const store = this.store;
|
||||
const filter = config.branchFilter();
|
||||
const parts = [store.baseSignature(), `filter:${filter.mode}:${filter.branch || ""}`];
|
||||
|
||||
for (const repo of store.repos) {
|
||||
parts.push(store.runsSignature(repo.key), store.pullsSignature(repo.key));
|
||||
parts.push(store.elapsedTick(store.runsFor(repo.key).runs));
|
||||
}
|
||||
return parts.join("|");
|
||||
}
|
||||
|
||||
roots() {
|
||||
const store = this.store;
|
||||
|
||||
|
||||
@@ -6,6 +6,29 @@
|
||||
const log = require("../util/log.js");
|
||||
const { message } = require("./nodes.js");
|
||||
|
||||
// The parts of a node that end up on screen; a change to any of them means the
|
||||
// row has to be redrawn.
|
||||
const RENDERED_FIELDS = [
|
||||
"name",
|
||||
"descriptiveText",
|
||||
"tooltip",
|
||||
"image",
|
||||
"path",
|
||||
"command",
|
||||
"contextValue",
|
||||
];
|
||||
|
||||
/** Drops nodes that are already covered by an ancestor in the same list. */
|
||||
function topmost(nodes) {
|
||||
const unique = [...new Set(nodes)];
|
||||
return unique.filter((node) => {
|
||||
for (let parent = node.parent; parent; parent = parent.parent) {
|
||||
if (unique.includes(parent)) return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
class NodeProvider {
|
||||
constructor(store) {
|
||||
this.store = store;
|
||||
@@ -51,6 +74,88 @@ class NodeProvider {
|
||||
this._roots = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuilds from the store and merges the result into the node objects Nova
|
||||
* is already holding, rather than replacing them.
|
||||
*
|
||||
* This is what lets the tree update as often as it likes without the view
|
||||
* jumping: a full `TreeView.reload()` rebuilds every row and drops the
|
||||
* scroll position, so instead this reports the smallest set of rows that
|
||||
* actually changed and only those get reloaded.
|
||||
*
|
||||
* Returns `{ full: true }` when the shape changed too much to patch,
|
||||
* `{ full: false, nodes }` for a targeted reload, or null when nothing
|
||||
* changed at all.
|
||||
*/
|
||||
async update() {
|
||||
const built = await this.roots();
|
||||
for (const root of built) root.parent = null;
|
||||
|
||||
if (!this._roots) {
|
||||
this._roots = built;
|
||||
return { full: true };
|
||||
}
|
||||
|
||||
const changed = [];
|
||||
this._roots = this._merge(this._roots, built, changed, null);
|
||||
|
||||
if (changed.includes(null)) return { full: true };
|
||||
if (!changed.length) return null;
|
||||
|
||||
return { full: false, nodes: topmost(changed) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconciles one level. Rows are matched by identifier and updated in
|
||||
* place; if the row set itself moved, the owner is rebuilt instead.
|
||||
*/
|
||||
_merge(previous, next, changed, owner) {
|
||||
const sameRows =
|
||||
previous.length === next.length &&
|
||||
previous.every((node, index) => node.identifier === next[index].identifier);
|
||||
|
||||
if (!sameRows) {
|
||||
for (const node of next) node.parent = owner;
|
||||
changed.push(owner);
|
||||
return next;
|
||||
}
|
||||
|
||||
return previous.map((node, index) => {
|
||||
const fresh = next[index];
|
||||
if (this._apply(node, fresh)) changed.push(node);
|
||||
|
||||
if (node.children && fresh.children) {
|
||||
node.children = this._merge(node.children, fresh.children, changed, node);
|
||||
} else if (node.children && fresh.load) {
|
||||
// An open row that fetches its own children: drop the cache so
|
||||
// the reload refetches, which is the running-job case.
|
||||
node.children = null;
|
||||
changed.push(node);
|
||||
}
|
||||
|
||||
return node;
|
||||
});
|
||||
}
|
||||
|
||||
/** Copies the fresh row's content onto the live node; true if visibly different. */
|
||||
_apply(node, fresh) {
|
||||
let dirty = false;
|
||||
for (const field of RENDERED_FIELDS) {
|
||||
if (node[field] !== fresh[field]) {
|
||||
node[field] = fresh[field];
|
||||
dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Carried across whether or not they are drawn: commands read them.
|
||||
node.data = fresh.data;
|
||||
node.repo = fresh.repo;
|
||||
node.load = fresh.load;
|
||||
node.expanded = fresh.expanded;
|
||||
|
||||
return dirty;
|
||||
}
|
||||
|
||||
async getChildren(element) {
|
||||
try {
|
||||
if (!element) {
|
||||
@@ -79,6 +184,33 @@ class NodeProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a rebuilt node by identifier, walking only branches the user has
|
||||
* open. That is enough to locate anything currently on screen, and it
|
||||
* avoids triggering a fetch for collapsed rows.
|
||||
*/
|
||||
async findByIdentifier(identifier) {
|
||||
if (!identifier) return null;
|
||||
|
||||
const walk = async (candidates) => {
|
||||
for (const candidate of candidates) {
|
||||
if (candidate.identifier === identifier) return candidate;
|
||||
if (!this._expanded.has(candidate.identifier)) continue;
|
||||
|
||||
const found = await walk(await this.getChildren(candidate));
|
||||
if (found) return found;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
return await walk(await this.getChildren(null));
|
||||
}
|
||||
|
||||
/** Overridden per section: what this section draws, as a comparable string. */
|
||||
signature() {
|
||||
return null;
|
||||
}
|
||||
|
||||
getParent(element) {
|
||||
return element ? element.parent : null;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,15 @@ const { NodeProvider } = require("./provider.js");
|
||||
const { node, message, errorNode } = nodes;
|
||||
|
||||
class PullRequestsProvider extends NodeProvider {
|
||||
// No elapsed clock here, so this section never redraws on run activity.
|
||||
signature() {
|
||||
const store = this.store;
|
||||
return [
|
||||
store.baseSignature(),
|
||||
...store.repos.map((repo) => store.pullsSignature(repo.key)),
|
||||
].join("|");
|
||||
}
|
||||
|
||||
roots() {
|
||||
const store = this.store;
|
||||
|
||||
|
||||
@@ -12,6 +12,16 @@ const { NodeProvider } = require("./provider.js");
|
||||
const { node, message, errorNode } = nodes;
|
||||
|
||||
class SettingsProvider extends NodeProvider {
|
||||
signature() {
|
||||
const store = this.store;
|
||||
return [
|
||||
store.baseSignature(),
|
||||
store.instancesSignature(),
|
||||
`aliases:${[...store.router.aliases.keys()].join(",")}`,
|
||||
...store.repos.map((repo) => store.settingsSignature(repo.key)),
|
||||
].join("|");
|
||||
}
|
||||
|
||||
roots() {
|
||||
const store = this.store;
|
||||
const baseUrls = store.router.baseUrls;
|
||||
|
||||
@@ -10,6 +10,17 @@ const { NodeProvider } = require("./provider.js");
|
||||
const { node, message, errorNode } = nodes;
|
||||
|
||||
class WorkflowsProvider extends NodeProvider {
|
||||
signature() {
|
||||
const store = this.store;
|
||||
const parts = [store.baseSignature()];
|
||||
|
||||
for (const repo of store.repos) {
|
||||
parts.push(store.runsSignature(repo.key));
|
||||
parts.push(store.elapsedTick(store.runsFor(repo.key).runs));
|
||||
}
|
||||
return parts.join("|");
|
||||
}
|
||||
|
||||
roots() {
|
||||
const store = this.store;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user