summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-27 18:51:43 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-27 18:51:43 +1000
commitadc2465f56f4f60fa8348d11330c42148fa779cb (patch)
treebb6dd2516376cb33b332776c27023d406b9bd227
parentclient patcher stuff (diff)
downloadserver-adc2465f56f4f60fa8348d11330c42148fa779cb.tar.xz
Don't fetch all members in guild in Member.addToGuild
-rw-r--r--src/util/entities/Guild.ts4
-rw-r--r--src/util/entities/Member.ts18
2 files changed, 18 insertions, 4 deletions
diff --git a/src/util/entities/Guild.ts b/src/util/entities/Guild.ts
index 8854fec0..169921be 100644
--- a/src/util/entities/Guild.ts
+++ b/src/util/entities/Guild.ts
@@ -43,11 +43,11 @@ import { Webhook } from "./Webhook";
 export const PublicGuildRelations = [
 	"channels",
 	"emojis",
-	"members",
 	"roles",
 	"stickers",
 	"voice_states",
-	"members.user",
+	// "members",		// TODO: These are public, but all members should not be fetched.
+	// "members.user",
 ];
 
 @Entity("guilds")
diff --git a/src/util/entities/Member.ts b/src/util/entities/Member.ts
index f2762adc..27c67c40 100644
--- a/src/util/entities/Member.ts
+++ b/src/util/entities/Member.ts
@@ -10,6 +10,7 @@ import {
 	JoinTable,
 	ManyToMany,
 	ManyToOne,
+	Not,
 	PrimaryGeneratedColumn,
 	RelationId,
 } from "typeorm";
@@ -287,6 +288,19 @@ export class Member extends BaseClassWithoutId {
 			relations: [...PublicGuildRelations, "system_channel"],
 		});
 
+		const memberCount = await Member.count({ where: { guild_id } });
+		const memberPreview = await Member.find({
+			where: {
+				guild_id,
+				user: {
+					sessions: {
+						status: Not("invisible" as "invisible")	// lol typescript?
+					}
+				}
+			},
+			take: 10,
+		});
+
 		if (
 			await Member.count({
 				where: { id: user.id, guild: { id: guild_id } },
@@ -342,8 +356,8 @@ export class Member extends BaseClassWithoutId {
 				event: "GUILD_CREATE",
 				data: {
 					...guild,
-					members: [...guild.members, { ...member, user }],
-					member_count: (guild.member_count || 0) + 1,
+					members: [...memberPreview, { ...member, user }],
+					member_count: memberCount + 1,
 					guild_hashes: {},
 					guild_scheduled_events: [],
 					joined_at: member.joined_at,