perf(messageSaver): passthrough bot messages without saving them

This commit is contained in:
Dragory 2021-10-17 08:13:08 +03:00
parent 44f5b77cc7
commit 1f4f27c26a
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

@ -188,6 +188,13 @@ export class GuildSavedMessages extends BaseGuildRepository<SavedMessage> {
return;
}
// Don't actually save bot messages. Just pass them through as if they were saved.
if (msg.author.bot) {
const fakeSavedMessage = buildEntity(SavedMessage, await this.msgToInsertReadyEntity(msg));
this.fireCreateEvents(fakeSavedMessage);
return;
}
await this.createFromMessages([msg], overrides);
}
@ -228,11 +235,15 @@ export class GuildSavedMessages extends BaseGuildRepository<SavedMessage> {
for (const item of items) {
// perf: save a db lookup and message content decryption by building the entity manually
const inserted = buildEntity(SavedMessage, item);
this.events.emit("create", [inserted]);
this.events.emit(`create:${item.id}`, [inserted]);
this.fireCreateEvents(inserted);
}
}
protected async fireCreateEvents(message: SavedMessage) {
this.events.emit("create", [message]);
this.events.emit(`create:${message.id}`, [message]);
}
async markAsDeleted(id): Promise<void> {
await this.messages
.createQueryBuilder("messages")