diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts
index e391b2ab..2446da63 100644
--- a/src/api/routes/channels/#channel_id/messages/index.ts
+++ b/src/api/routes/channels/#channel_id/messages/index.ts
@@ -121,6 +121,7 @@ router.get(
const query: FindManyOptions<Message> & {
where: { id?: FindOperator<string> | FindOperator<string>[] };
} = {
+ relationLoadStrategy: "query",
order: { timestamp: "DESC" },
take: limit,
where: { channel_id },
@@ -133,16 +134,6 @@ router.get(
mention_channels: true,
sticker_items: true,
attachments: true,
- referenced_message: {
- author: true,
- webhook: true,
- application: true,
- mentions: true,
- mention_roles: true,
- mention_channels: true,
- sticker_items: true,
- attachments: true,
- },
thread: {
recipients: {
user: true,
@@ -156,6 +147,7 @@ router.get(
if (around) {
query.take = Math.floor(limit / 2);
if (query.take != 0) {
+ console.time("Query");
const [right, left] = await Promise.all([
Message.find({
...query,
@@ -167,6 +159,7 @@ router.get(
order: { timestamp: "ASC" },
}),
]);
+ console.timeEnd("Query");
left.push(...right);
messages = left.sort((a, b) => a.timestamp.getTime() - b.timestamp.getTime());
} else {
@@ -192,6 +185,7 @@ router.get(
messages = await Message.find(query);
}
+ await Message.fillReplies(messages);
const endpoint = Config.get().cdn.endpointPublic;
const ret = messages.map((x: Message) => {
@@ -267,24 +261,6 @@ router.get(
}),
);
- // polyfill message references for old messages
- await Promise.all(
- ret
- .filter((msg) => msg.message_reference && !msg.referenced_message?.id && msg.message_reference.message_id)
- .map(async (msg) => {
- const whereOptions: { id: string; guild_id?: string; channel_id?: string } = {
- id: msg.message_reference!.message_id as string,
- };
- if (msg.message_reference!.guild_id) whereOptions.guild_id = msg.message_reference!.guild_id;
- if (msg.message_reference!.channel_id) whereOptions.channel_id = msg.message_reference!.channel_id;
-
- msg.referenced_message = await Message.findOne({
- where: whereOptions,
- relations: { author: true, mentions: true, mention_roles: true, mention_channels: true },
- });
- }),
- );
-
return res.json(ret);
},
);
|