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