From 83cd6652ba3a61b070d689c5dc72df3e41769794 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Wed, 2 Apr 2025 18:44:40 +0200 Subject: [PATCH 1/2] chore: remove needless query when sending clan invite --- src/controllers/api/addToGuildController.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/controllers/api/addToGuildController.ts b/src/controllers/api/addToGuildController.ts index ef75f551..a069220f 100644 --- a/src/controllers/api/addToGuildController.ts +++ b/src/controllers/api/addToGuildController.ts @@ -35,22 +35,17 @@ export const addToGuildController: RequestHandler = async (req, res) => { res.status(400).json("Invalid permission"); } - if ( - await GuildMember.exists({ + try { + await GuildMember.insertOne({ accountId: account._id, - guildId: payload.GuildId.$oid - }) - ) { + guildId: payload.GuildId.$oid, + status: 2 // outgoing invite + }); + } catch (e) { res.status(400).json("User already invited to clan"); return; } - await GuildMember.insertOne({ - accountId: account._id, - guildId: payload.GuildId.$oid, - status: 2 // outgoing invite - }); - const senderInventory = await getInventory(senderAccount._id.toString(), "ActiveAvatarImageType"); await createMessage(account._id, [ { -- 2.47.2 From e33bbb0f9561e2f8993490894f8f4651f422780e Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Wed, 2 Apr 2025 22:26:05 +0200 Subject: [PATCH 2/2] log caught member insert errors for debugging purposes --- src/controllers/api/addToGuildController.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/controllers/api/addToGuildController.ts b/src/controllers/api/addToGuildController.ts index a069220f..d2a89df4 100644 --- a/src/controllers/api/addToGuildController.ts +++ b/src/controllers/api/addToGuildController.ts @@ -42,6 +42,7 @@ export const addToGuildController: RequestHandler = async (req, res) => { status: 2 // outgoing invite }); } catch (e) { + logger.debug(`guild invite failed due to ${String(e)}`); res.status(400).json("User already invited to clan"); return; } @@ -87,7 +88,7 @@ export const addToGuildController: RequestHandler = async (req, res) => { RequestExpiry: new Date(Date.now() + 14 * 86400 * 1000) // TOVERIFY: I can't find any good information about this with regards to live, but 2 weeks seem reasonable. }); } catch (e) { - // Assuming this is "E11000 duplicate key error" due to the guildId-accountId unique index. + logger.debug(`alliance invite failed due to ${String(e)}`); res.status(400).send("Already requested"); } res.end(); -- 2.47.2