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:
parent
b4a3a03558
commit
adc2465f56
@ -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")
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user