summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-07 15:54:27 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-04-07 15:54:27 +0200
commit25d901e8e1399afa050b078b88662afede5bd9d1 (patch)
tree9c27c1db512f02787a230a7b04f53df2c0c6e5d7 /src/util
parentfix toObject type (diff)
downloadserver-25d901e8e1399afa050b078b88662afede5bd9d1.tar.xz
getPermission use cache
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Permissions.ts10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/util/Permissions.ts b/src/util/Permissions.ts
index 4bad70d3..fb7e0b88 100644
--- a/src/util/Permissions.ts
+++ b/src/util/Permissions.ts
@@ -147,21 +147,21 @@ export async function getPermission(
 	user_id: string,
 	guild_id: string,
 	channel_id?: string,
-	cache?: { channel?: ChannelDocument | null; member?: MemberDocument | null }
+	cache?: { channel?: ChannelDocument | null; member?: MemberDocument | null; guild?: GuildDocument | null }
 ) {
-	var { channel, member } = cache || {};
+	var { channel, member, guild } = cache || {};
 
-	const guild = await GuildModel.findOne({ id: guild_id }, { owner_id: true }).exec();
+	if (!guild) guild = await GuildModel.findOne({ id: guild_id }, { owner_id: true }).exec();
 	if (!guild) throw new Error("Guild not found");
 	if (guild.owner_id === user_id) return new Permissions(Permissions.FLAGS.ADMINISTRATOR);
 
-	member = await MemberModel.findOne({ guild_id, id: user_id }, "roles").exec();
+	if (!member) member = await MemberModel.findOne({ guild_id, id: user_id }, "roles").exec();
 	if (!member) throw new Error("Member not found");
 
 	var roles = await RoleModel.find({ guild_id, id: { $in: member.roles } })
 		.lean()
 		.exec();
-	if (channel_id) {
+	if (channel_id && !channel) {
 		channel = await ChannelModel.findOne({ id: channel_id }, "permission_overwrites").exec();
 	}