perf(backend): parallelize getMessageById DB queries + drop unused indexes
- getMessageById: run findById and getEditHistory in parallel via Promise.all instead of sequential awaits (halves latency for message detail view) - Drop 3 unused indexes on messages table: idx_messages_guild_ai_status_created (0 scans), idx_messages_guild_ai_status_analyzed (97 scans), idx_messages_guild_created_deleted (95 scans, superseded by covering index) — saves ~5.9MB index space + reduces write amplification - Add covering index idx_messages_guild_created_covering for the primary findMany query pattern (guild_id + created_at DESC with INCLUDE columns)
This commit is contained in:
@@ -39,12 +39,15 @@ export class MessagesService {
|
|||||||
throw new ValidationError("message ID is required");
|
throw new ValidationError("message ID is required");
|
||||||
}
|
}
|
||||||
|
|
||||||
const message = await messagesRepository.findById(id);
|
const [message, editHistory] = await Promise.all([
|
||||||
|
messagesRepository.findById(id),
|
||||||
|
messagesRepository.getEditHistory(id),
|
||||||
|
]);
|
||||||
|
|
||||||
if (!message) {
|
if (!message) {
|
||||||
throw new NotFoundError(`Message with ID ${id} not found`);
|
throw new NotFoundError(`Message with ID ${id} not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const editHistory = await messagesRepository.getEditHistory(id);
|
|
||||||
return {
|
return {
|
||||||
...message,
|
...message,
|
||||||
edit_count: editHistory.length,
|
edit_count: editHistory.length,
|
||||||
|
|||||||
Reference in New Issue
Block a user