1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-25 19:52:36 +01:00

Don't fetch all members in guild in Member.addToGuild

This commit is contained in:
Madeline 2022-09-27 18:51:43 +10:00
parent b4a3a03558
commit adc2465f56
No known key found for this signature in database
GPG Key ID: 1958E017C36F2E47
2 changed files with 18 additions and 4 deletions

View File

@ -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")

View File

@ -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,