From 92cf85084f9accb617743ff80900f21639a2ee8f Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Thu, 3 Apr 2025 06:17:38 -0700 Subject: [PATCH] chore: remove needless query when sending clan invite (#1434) Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1434 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com> --- src/controllers/api/addToGuildController.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/controllers/api/addToGuildController.ts b/src/controllers/api/addToGuildController.ts index ef75f551..d2a89df4 100644 --- a/src/controllers/api/addToGuildController.ts +++ b/src/controllers/api/addToGuildController.ts @@ -35,22 +35,18 @@ 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) { + logger.debug(`guild invite failed due to ${String(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, [ { @@ -92,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();