perf: reduce database data transfer

This commit is contained in:
Isaac 2022-10-26 00:46:07 +01:00
parent 09095f71c1
commit 7417005782
No known key found for this signature in database
GPG Key ID: 0DE40AE37BBA5C33

View File

@ -28,6 +28,10 @@ module.exports = class TicketCompleter extends Autocompleter {
let tickets = await this.cache.get(cacheKey); let tickets = await this.cache.get(cacheKey);
if (!tickets) { if (!tickets) {
const { locale } = await client.prisma.guild.findUnique({
select: { locale: true },
where: { id: guildId },
});
tickets = await client.prisma.ticket.findMany({ tickets = await client.prisma.ticket.findMany({
include: { include: {
category: { category: {
@ -36,7 +40,6 @@ module.exports = class TicketCompleter extends Autocompleter {
name: true, name: true,
}, },
}, },
guild: true,
}, },
where: { where: {
createdById: userId, createdById: userId,
@ -45,7 +48,7 @@ module.exports = class TicketCompleter extends Autocompleter {
}, },
}); });
tickets = tickets.map(ticket => { 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 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; 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}`; ticket._name = `${category} #${ticket.number} (${date}) ${topic}`;