From 69f418673910c2ac1a56bb984cb052d33fdbf831 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Thu, 21 Mar 2024 00:10:13 -0400 Subject: [PATCH] fix(striker-ui-api): empty existing database hash before re-reading to remove deleted data --- striker-ui-api/src/lib/accessModule.ts | 22 +++++++++++++++++++ .../host/deleteHostConnection.ts | 9 ++++++++ 2 files changed, 31 insertions(+) diff --git a/striker-ui-api/src/lib/accessModule.ts b/striker-ui-api/src/lib/accessModule.ts index 7c6f18f1..3324ea3c 100644 --- a/striker-ui-api/src/lib/accessModule.ts +++ b/striker-ui-api/src/lib/accessModule.ts @@ -331,6 +331,24 @@ const getData = async (...keys: string[]) => { return data; }; +const mutateData = async (args: { + keys: string[]; + operator: string; + value: string; +}): Promise => { + const { keys, operator, value } = args; + + const chain = `data->${keys.join('->')}`; + + const { + sub_results: [data], + } = await access.interact<{ sub_results: [T] }>('x', chain, operator, value); + + shvar(data, `${chain} data: `); + + return data; +}; + const getAnvilData = async () => { await subroutine('get_anvils'); @@ -338,6 +356,9 @@ const getAnvilData = async () => { }; const getDatabaseConfigData = async () => { + // Empty the existing data->database hash before re-reading updated values. + await mutateData({ keys: ['database'], operator: '=', value: '{}' }); + const [ecode] = await subroutine<[ecode: string]>('read_config', { pre: ['Storage'], }); @@ -494,6 +515,7 @@ export { getPeerData, getUpsSpec, getVncinfo, + mutateData, query, subroutine as sub, write, diff --git a/striker-ui-api/src/lib/request_handlers/host/deleteHostConnection.ts b/striker-ui-api/src/lib/request_handlers/host/deleteHostConnection.ts index 2470bf05..7f639809 100644 --- a/striker-ui-api/src/lib/request_handlers/host/deleteHostConnection.ts +++ b/striker-ui-api/src/lib/request_handlers/host/deleteHostConnection.ts @@ -18,6 +18,15 @@ export const deleteHostConnection: RequestHandler< const hostUuid = toHostUUID(key); const peerHostUuids = body[key]; + /** + * Removing one or more peer of a striker doesn't update the globals in + * access module's memory, meaning there will be broken references to the + * removed peer for, i.e., database connections. + * + * TODO: find a solution to update the necessary pieces after removing + * peer(s). + */ + for (const peerHostUuid of peerHostUuids) { try { await job({