Merge pull request #3019 from gradido/federation-remove-duplicate-db-query

refactor(federation): removed (potential) duplicate db query
This commit is contained in:
Ulf Gebhardt 2023-06-09 14:27:39 +02:00 committed by GitHub
commit 6fe993244f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -215,14 +215,7 @@ async function writeFederatedHomeCommunityEntries(pubKey: string): Promise<Commu
async function writeHomeCommunityEntry(pubKey: string): Promise<void> {
try {
// check for existing homeCommunity entry
let homeCom = await DbCommunity.findOne({
foreign: false,
publicKey: Buffer.from(pubKey),
})
if (!homeCom) {
// check if a homecommunity with a different publicKey still exists
homeCom = await DbCommunity.findOne({ foreign: false })
}
let homeCom = await DbCommunity.findOne({ foreign: false })
if (homeCom) {
// simply update the existing entry, but it MUST keep the ID and UUID because of possible relations
homeCom.publicKey = Buffer.from(pubKey)