summary refs log tree commit diff
diff options
context:
space:
mode:
authorSamuel <34555296+Flam3rboy@users.noreply.github.com>2023-03-17 19:18:57 +0100
committerSamuel <34555296+Flam3rboy@users.noreply.github.com>2023-03-17 19:18:57 +0100
commit5ba7c6b5bc87d5874de881f675ad92811837aaac (patch)
tree489af6c5ed1bbda8e633583d5b8bfdfc8c759e4a
parentfeat: better-sqlite3 support (diff)
downloadserver-5ba7c6b5bc87d5874de881f675ad92811837aaac.tar.xz
perf: optimize getPermission()
-rw-r--r--src/util/util/Permissions.ts33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/util/util/Permissions.ts b/src/util/util/Permissions.ts
index 996c72ea..4aeb9268 100644
--- a/src/util/util/Permissions.ts
+++ b/src/util/util/Permissions.ts
@@ -257,23 +257,26 @@ export async function getPermission(
 	}
 
 	if (guild_id) {
-		guild = await Guild.findOneOrFail({
-			where: { id: guild_id },
-			select: ["id", "owner_id", ...(opts.guild_select || [])],
-			relations: opts.guild_relations,
-		});
+		const result = await Promise.all([
+			Guild.findOneOrFail({
+				where: { id: guild_id },
+				select: ["id", "owner_id", ...(opts.guild_select || [])],
+				relations: opts.guild_relations,
+			}),
+			Member.findOneOrFail({
+				where: { guild_id, id: user_id },
+				relations: ["roles", ...(opts.member_relations || [])],
+				// select: [
+				// "id",		// TODO: Bug in typeorm? adding these selects breaks the query.
+				// "roles",
+				// ...(opts.member_select || []),
+				// ],
+			}),
+		]);
+		guild = result[0];
+		member = result[1];
 		if (guild.owner_id === user_id)
 			return new Permissions(Permissions.FLAGS.ADMINISTRATOR);
-
-		member = await Member.findOneOrFail({
-			where: { guild_id, id: user_id },
-			relations: ["roles", ...(opts.member_relations || [])],
-			// select: [
-			// "id",		// TODO: Bug in typeorm? adding these selects breaks the query.
-			// "roles",
-			// ...(opts.member_select || []),
-			// ],
-		});
 	}
 
 	let recipient_ids = channel?.recipients?.map((x) => x.user_id);