mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-11-05 12:23:09 +02:00
Add category cache
This commit is contained in:
parent
3318ddcaa6
commit
7b692facc1
@ -7,6 +7,7 @@ const {
|
||||
TextInputStyle,
|
||||
} = require('discord.js');
|
||||
const emoji = require('node-emoji');
|
||||
const ms = require('ms');
|
||||
|
||||
module.exports = class TicketManager {
|
||||
constructor(client) {
|
||||
@ -23,13 +24,20 @@ module.exports = class TicketManager {
|
||||
async create({
|
||||
categoryId, interaction, topic, reference,
|
||||
}) {
|
||||
const category = await this.client.prisma.category.findUnique({
|
||||
include: {
|
||||
guild: true,
|
||||
questions: true,
|
||||
},
|
||||
where: { id: Number(categoryId) },
|
||||
});
|
||||
const cacheKey = `cache/category+guild+questions:${categoryId}`;
|
||||
let category = await this.client.keyv.get(cacheKey);
|
||||
|
||||
if (!category) {
|
||||
category = await this.client.prisma.category.findUnique({
|
||||
include: {
|
||||
guild: true,
|
||||
questions: true,
|
||||
},
|
||||
where: { id: Number(categoryId) },
|
||||
});
|
||||
this.client.keyv.set(cacheKey, category, ms('5m'));
|
||||
}
|
||||
|
||||
|
||||
// TODO: if member !required roles -> stop
|
||||
|
||||
@ -41,6 +49,8 @@ module.exports = class TicketManager {
|
||||
|
||||
// TODO: if cooldown -> stop
|
||||
|
||||
// TODO: if 10s ratelimit -> stop
|
||||
|
||||
const getMessage = this.client.i18n.getLocale(category.guild.locale);
|
||||
|
||||
if (category.questions.length >= 1) {
|
||||
|
Loading…
Reference in New Issue
Block a user