From 741700578235e220e90f4bb1e67d2c9a3aec8ca7 Mon Sep 17 00:00:00 2001 From: Isaac Date: Wed, 26 Oct 2022 00:46:07 +0100 Subject: [PATCH] perf: reduce database data transfer --- src/autocomplete/ticket.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/autocomplete/ticket.js b/src/autocomplete/ticket.js index e6ac012..df38807 100644 --- a/src/autocomplete/ticket.js +++ b/src/autocomplete/ticket.js @@ -28,6 +28,10 @@ module.exports = class TicketCompleter extends Autocompleter { let tickets = await this.cache.get(cacheKey); if (!tickets) { + const { locale } = await client.prisma.guild.findUnique({ + select: { locale: true }, + where: { id: guildId }, + }); tickets = await client.prisma.ticket.findMany({ include: { category: { @@ -36,7 +40,6 @@ module.exports = class TicketCompleter extends Autocompleter { name: true, }, }, - guild: true, }, where: { createdById: userId, @@ -45,7 +48,7 @@ module.exports = class TicketCompleter extends Autocompleter { }, }); tickets = tickets.map(ticket => { - const date = new Date(ticket.createdAt).toLocaleString([ticket.guild.locale, 'en-GB'], { dateStyle: 'short' }); + const date = new Date(ticket.createdAt).toLocaleString([locale, 'en-GB'], { dateStyle: 'short' }); const topic = ticket.topic ? '- ' + decrypt(ticket.topic).substring(0, 50) : ''; const category = emoji.hasEmoji(ticket.category.emoji) ? emoji.get(ticket.category.emoji) + ' ' + ticket.category.name : ticket.category.name; ticket._name = `${category} #${ticket.number} (${date}) ${topic}`;