From db36a05a74305fca0698bf143e9d9760dffde0d0 Mon Sep 17 00:00:00 2001 From: jolavillette Date: Thu, 13 Aug 2026 13:38:49 +0200 Subject: [PATCH] network: cache the location details, and stop waiting on a catch that never fires The version and the short invite of a node do not change while the web UI is open, but the dialog asked the core again on every open, showing "Loading..." each time. They are now cached by node id. The two .catch() handlers could not do what they were written for: rsJsonApiRequest never rejects, it resolves undefined when a request fails. They only ever ran by accident, when reading .body of that undefined threw a TypeError inside the .then. The failure is now read off the resolved value, where it actually is. --- webui-src/app/network/network_details_tab.js | 37 +++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/webui-src/app/network/network_details_tab.js b/webui-src/app/network/network_details_tab.js index d3baaa4..61b7637 100644 --- a/webui-src/app/network/network_details_tab.js +++ b/webui-src/app/network/network_details_tab.js @@ -51,6 +51,11 @@ const ConfirmRemove = () => { }; }; +// Version and short invite of a node do not change while the web UI is open, +// and the dialog is reopened often. Cached by node id so that reopening it +// paints filled in, instead of showing "Loading..." and asking the core again. +const locationDetailsCache = {}; + const LocationDetails = () => { let activeTab = 'details'; let version = 'Loading...'; @@ -58,26 +63,32 @@ const LocationDetails = () => { return { oninit: (vnode) => { - rs.rsJsonApiRequest('/rsGossipDiscovery/getPeerVersion', { id: vnode.attrs.loc.id }) + const nodeId = vnode.attrs.loc.id; + const cached = locationDetailsCache[nodeId]; + if (cached) { + version = cached.version; + retroshareId = cached.retroshareId; + return; + } + locationDetailsCache[nodeId] = { version, retroshareId }; + + // rsJsonApiRequest never rejects: it resolves undefined when the request + // fails, so the failure has to be read off the resolved value rather than + // waited for in a catch. + rs.rsJsonApiRequest('/rsGossipDiscovery/getPeerVersion', { id: nodeId }) .then((response) => { - version = response.body && response.body.retval + version = response && response.body && response.body.retval ? response.body.version || 'Unknown' - : 'Unknown'; - m.redraw(); - }) - .catch(() => { - version = 'Unavailable'; + : 'Unavailable'; + locationDetailsCache[nodeId].version = version; m.redraw(); }); - rs.rsJsonApiRequest('/rsPeers/getShortInvite', { sslId: vnode.attrs.loc.id }) + rs.rsJsonApiRequest('/rsPeers/getShortInvite', { sslId: nodeId }) .then((response) => { - retroshareId = response.body && response.body.retval + retroshareId = response && response.body && response.body.retval ? cleanRetroshareId(response.body.invite) || 'Unavailable' : 'Unavailable'; - m.redraw(); - }) - .catch(() => { - retroshareId = 'Unavailable'; + locationDetailsCache[nodeId].retroshareId = retroshareId; m.redraw(); }); },