summary refs log tree commit diff
path: root/src/api/routes/guilds
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-04-11 13:17:51 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-04-11 13:17:51 +1000
commit7a2a41be3ec8af8b155a241cbbc2507082f40eae (patch)
treef66a805c427fcd6a89bd3b4ce3516c93dd3e1019 /src/api/routes/guilds
parentmember-counts route (diff)
downloadserver-7a2a41be3ec8af8b155a241cbbc2507082f40eae.tar.xz
Don't fetch the entire role relation when counting member ids
Diffstat (limited to 'src/api/routes/guilds')
-rw-r--r--src/api/routes/guilds/#guild_id/roles/#role_id/member-ids.ts18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/api/routes/guilds/#guild_id/roles/#role_id/member-ids.ts b/src/api/routes/guilds/#guild_id/roles/#role_id/member-ids.ts
index e0e7bd20..b086193e 100644
--- a/src/api/routes/guilds/#guild_id/roles/#role_id/member-ids.ts
+++ b/src/api/routes/guilds/#guild_id/roles/#role_id/member-ids.ts
@@ -24,17 +24,19 @@ const router = Router();
 
 router.get("/", route({}), async (req: Request, res: Response) => {
 	const { guild_id, role_id } = req.params;
-	await Member.IsInGuildOrFail(req.user_id, guild_id);
+
+	// TODO: Is this route really not paginated?
 	const members = await Member.find({
 		select: ["id"],
-		relations: ["roles"],
+		where: {
+			roles: {
+				id: role_id,
+			},
+			guild_id,
+		},
 	});
-	const member_ids = members
-		.filter((member) => {
-			return member.roles.map((role) => role.id).includes(role_id);
-		})
-		.map((member) => member.id);
-	return res.json(member_ids);
+
+	return res.json(members.map((x) => x.id));
 });
 
 export default router;