perf: cache staff roles

This commit is contained in:
Isaac
2023-01-12 17:20:21 +00:00
parent db94ab770d
commit d7e1b05586
3 changed files with 38 additions and 10 deletions

View File

@@ -1,16 +1,19 @@
const { logAdminEvent } = require('../../../../../../../lib/logging');
const { updateStaffRoles } = require('../../../../../../../lib/users');
const { randomUUID } = require('crypto');
module.exports.delete = fastify => ({
handler: async (req, res) => {
/** @type {import('client')} */
const client = res.context.config.client;
const guildId = req.params.guild;
const guild = client.guilds.cache.get(req.params.guild);
const categoryId = Number(req.params.category);
const original = categoryId && await client.prisma.category.findUnique({ where: { id: categoryId } });
if (!original || original.guildId !== guildId) return res.status(404).send(new Error('Not Found'));
if (!original || original.guildId !== guild.id) return res.status(404).send(new Error('Not Found'));
const category = await client.prisma.category.delete({ where: { id: categoryId } });
await updateStaffRoles(guild);
logAdminEvent(client, {
action: 'delete',
guildId: req.params.guild,
@@ -137,6 +140,8 @@ module.exports.patch = fastify => ({
where: { id: categoryId },
});
await updateStaffRoles(guild);
logAdminEvent(client, {
action: 'update',
diff: {

View File

@@ -1,4 +1,5 @@
const { logAdminEvent } = require('../../../../../../lib/logging');
const { updateStaffRoles } = require('../../../../../../lib/users');
const emoji = require('node-emoji');
const { ChannelType: { GuildCategory } } = require('discord.js');
const ms = require('ms');
@@ -93,6 +94,8 @@ module.exports.post = fastify => ({
},
});
await updateStaffRoles(guild);
logAdminEvent(client, {
action: 'create',
guildId: guild.id,