mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-11-17 09:23:07 +02:00
fix: update cache when tags are updated
This commit is contained in:
parent
5d86d9464d
commit
9fc1130c4c
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "discord-tickets",
|
||||
"version": "4.0.0-beta.2",
|
||||
"version": "4.0.0-beta.3",
|
||||
"private": "true",
|
||||
"description": "An open-source Discord bot for ticket management",
|
||||
"main": "src/",
|
||||
|
@ -1,3 +1,4 @@
|
||||
const ms = require('ms');
|
||||
const { logAdminEvent } = require('../../../../../../lib/logging');
|
||||
|
||||
module.exports.delete = fastify => ({
|
||||
@ -10,6 +11,17 @@ module.exports.delete = fastify => ({
|
||||
if (original.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
|
||||
const tag = await client.prisma.tag.delete({ where: { id: tagId } });
|
||||
|
||||
const cacheKey = `cache/guild-tags:${guildId}`;
|
||||
client.keyv.set(cacheKey, await client.prisma.tag.findMany({
|
||||
select: {
|
||||
content: true,
|
||||
id: true,
|
||||
name: true,
|
||||
regex: true,
|
||||
},
|
||||
where: { guildId: guildId },
|
||||
}), ms('1h'));
|
||||
|
||||
logAdminEvent(client, {
|
||||
action: 'delete',
|
||||
guildId: req.params.guild,
|
||||
@ -62,6 +74,17 @@ module.exports.patch = fastify => ({
|
||||
where: { id: tagId },
|
||||
});
|
||||
|
||||
const cacheKey = `cache/guild-tags:${guildId}`;
|
||||
client.keyv.set(cacheKey, await client.prisma.tag.findMany({
|
||||
select: {
|
||||
content: true,
|
||||
id: true,
|
||||
name: true,
|
||||
regex: true,
|
||||
},
|
||||
where: { guildId: guildId },
|
||||
}), ms('1h'));
|
||||
|
||||
logAdminEvent(client, {
|
||||
action: 'update',
|
||||
diff: {
|
||||
|
@ -1,3 +1,4 @@
|
||||
const ms = require('ms');
|
||||
const { logAdminEvent } = require('../../../../../../lib/logging');
|
||||
|
||||
module.exports.get = fastify => ({
|
||||
@ -29,6 +30,24 @@ module.exports.post = fastify => ({
|
||||
},
|
||||
});
|
||||
|
||||
const cacheKey = `cache/guild-tags:${guild.id}`;
|
||||
let tags = await client.keyv.get(cacheKey);
|
||||
if (!tags) {
|
||||
tags = await client.prisma.tag.findMany({
|
||||
select: {
|
||||
content: true,
|
||||
id: true,
|
||||
name: true,
|
||||
regex: true,
|
||||
},
|
||||
where: { guildId: guild.id },
|
||||
});
|
||||
client.keyv.set(cacheKey, tags, ms('1h'));
|
||||
} else {
|
||||
tags.push(tag);
|
||||
client.keyv.set(cacheKey, tags, ms('1h'));
|
||||
}
|
||||
|
||||
logAdminEvent(client, {
|
||||
action: 'create',
|
||||
guildId: guild.id,
|
||||
|
Loading…
Reference in New Issue
Block a user