mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-11 05:02:37 +01:00
⚡ speed up message query
This commit is contained in:
parent
625853a47e
commit
f38f79b70c
@ -11,7 +11,7 @@ import {
|
||||
Message,
|
||||
MessageCreateEvent,
|
||||
uploadFile,
|
||||
Member,
|
||||
Member
|
||||
} from "@fosscord/util";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { handleMessage, postHandleMessage, route } from "@fosscord/api";
|
||||
@ -187,40 +187,34 @@ router.post(
|
||||
|
||||
message = await message.save();
|
||||
|
||||
await channel.assign({ last_message_id: message.id }).save();
|
||||
|
||||
//gosh
|
||||
var member = await Member.findOneOrFail({
|
||||
where: { id: req.user_id },
|
||||
});
|
||||
await member.assign({ last_message_id: message.id })
|
||||
await member.save(); //why does member.assign here return void?
|
||||
|
||||
if (channel.isDm()) {
|
||||
const channel_dto = await DmChannelDTO.from(channel);
|
||||
|
||||
for (let recipient of channel.recipients!) {
|
||||
//Only one recipients should be closed here, since in group DMs the recipient is deleted not closed
|
||||
|
||||
await Promise.all(
|
||||
channel.recipients!.map((recipient) => {
|
||||
if (recipient.closed) {
|
||||
await emitEvent({
|
||||
recipient.closed = false;
|
||||
return Promise.all([
|
||||
recipient.save(),
|
||||
emitEvent({
|
||||
event: "CHANNEL_CREATE",
|
||||
data: channel_dto.excludedRecipients([recipient.user_id]),
|
||||
user_id: recipient.user_id
|
||||
});
|
||||
})
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
//Only one recipients should be closed here, since in group DMs the recipient is deleted not closed
|
||||
await Promise.all(
|
||||
channel
|
||||
.recipients!.filter((r) => r.closed)
|
||||
.map(async (r) => {
|
||||
r.closed = false;
|
||||
return await r.save();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
await emitEvent({ event: "MESSAGE_CREATE", channel_id: channel_id, data: message } as MessageCreateEvent);
|
||||
await Promise.all([
|
||||
channel.assign({ last_message_id: message.id }).save(),
|
||||
new Member({ id: req.user_id, last_message_id: message.id }).save(),
|
||||
emitEvent({ event: "MESSAGE_CREATE", channel_id: channel_id, data: message } as MessageCreateEvent)
|
||||
]);
|
||||
|
||||
postHandleMessage(message).catch((e) => {}); // no await as it shouldnt block the message send function and silently catch error
|
||||
|
||||
return res.json(message);
|
||||
|
Loading…
Reference in New Issue
Block a user