From 2ec903ce2f1f21c5cdc000a34da541aa300e4a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Fri, 3 Feb 2023 17:31:23 +0100 Subject: [PATCH] insert HomeCommunity-Entries before starting dht-announcement --- dht-node/src/dht_node/index.ts | 39 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/dht-node/src/dht_node/index.ts b/dht-node/src/dht_node/index.ts index 3dffcb1ac..5ea373231 100644 --- a/dht-node/src/dht_node/index.ts +++ b/dht-node/src/dht_node/index.ts @@ -200,26 +200,27 @@ async function writeHomeCommunityEnries(pubKey: any): Promise { } return comApi }) - - homeApiVersions.forEach(async function (homeApi) { - const variables = { - foreign: false, - apiVersion: homeApi.api, - endPoint: homeApi.url, - publicKey: pubKey.toString('hex'), + try { + // first remove privious existing homeCommunity entries + const homeComs = await DbCommunity.find({ foreign: false }) + if (homeComs.length > 0) { + await DbCommunity.remove(homeComs) } - // this will NOT update the updatedAt column, to distingue between a normal update and the last announcement - await DbCommunity.createQueryBuilder() - .insert() - .into(DbCommunity) - .values(variables) - .orUpdate({ - conflict_target: ['id', 'foreign', 'publicKey', 'apiVersion'], - overwrite: ['foreign', 'api_version', 'end_point', 'public_key'], - }) - .execute() - logger.info(`federation home-community upserted successfully...`) - }) + + homeApiVersions.forEach(async function (homeApi) { + const homeCom = new DbCommunity() + homeCom.foreign = false + homeCom.apiVersion = homeApi.api + homeCom.endPoint = homeApi.url + homeCom.publicKey = pubKey.toString('hex') + + // this will NOT update the updatedAt column, to distingue between a normal update and the last announcement + await DbCommunity.insert(homeCom) + logger.info(`federation home-community inserted successfully: ${homeCom}`) + }) + } catch (err) { + throw new Error(`Federation: Error writing HomeCommunity-Entries: ${err}`) + } return homeApiVersions }