perf: optimize getPermission()

This commit is contained in:
Samuel 2023-03-17 19:18:57 +01:00
parent 197f1aacd2
commit 5ba7c6b5bc

View File

@ -257,15 +257,13 @@ export async function getPermission(
} }
if (guild_id) { if (guild_id) {
guild = await Guild.findOneOrFail({ const result = await Promise.all([
Guild.findOneOrFail({
where: { id: guild_id }, where: { id: guild_id },
select: ["id", "owner_id", ...(opts.guild_select || [])], select: ["id", "owner_id", ...(opts.guild_select || [])],
relations: opts.guild_relations, relations: opts.guild_relations,
}); }),
if (guild.owner_id === user_id) Member.findOneOrFail({
return new Permissions(Permissions.FLAGS.ADMINISTRATOR);
member = await Member.findOneOrFail({
where: { guild_id, id: user_id }, where: { guild_id, id: user_id },
relations: ["roles", ...(opts.member_relations || [])], relations: ["roles", ...(opts.member_relations || [])],
// select: [ // select: [
@ -273,7 +271,12 @@ export async function getPermission(
// "roles", // "roles",
// ...(opts.member_select || []), // ...(opts.member_select || []),
// ], // ],
}); }),
]);
guild = result[0];
member = result[1];
if (guild.owner_id === user_id)
return new Permissions(Permissions.FLAGS.ADMINISTRATOR);
} }
let recipient_ids = channel?.recipients?.map((x) => x.user_id); let recipient_ids = channel?.recipients?.map((x) => x.user_id);