Await guild creation to fix a race condition

`Promise.all(...)` runs these simultaneously, yet role depends on the
guild to be created first. This can lead to a race condition. I've
awaited role creation too because the call to `Member.addToGuild(...)`
relies on the role to be created.
This commit is contained in:
Zane Helton 2025-06-28 18:02:54 -04:00 committed by Madeline
parent 4772731a17
commit ff692c19b7

View File

@ -140,14 +140,14 @@ router.post(
const guild_id = Snowflake.generate(); const guild_id = Snowflake.generate();
const [guild] = await Promise.all([ const guild = await Guild.create({
Guild.create({
...body, ...body,
...template.serialized_source_guild, ...template.serialized_source_guild,
id: guild_id, id: guild_id,
owner_id: req.user_id, owner_id: req.user_id,
}).save(), }).save();
Role.create({
await Role.create({
id: guild_id, id: guild_id,
guild_id: guild_id, guild_id: guild_id,
color: 0, color: 0,
@ -157,8 +157,7 @@ router.post(
name: "@everyone", name: "@everyone",
permissions: BigInt("2251804225").toString(), // TODO: where did this come from? permissions: BigInt("2251804225").toString(), // TODO: where did this come from?
position: 0, position: 0,
}).save(), }).save();
]);
await Member.addToGuild(req.user_id, guild_id); await Member.addToGuild(req.user_id, guild_id);