mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 04:25:01 +00:00
perf: use a memory cache for AutoReactions
This commit is contained in:
parent
31f18ba27f
commit
d09d6b776a
5 changed files with 24 additions and 3 deletions
|
@ -6,6 +6,7 @@ import { missingPermissionError } from "../../../utils/missingPermissionError";
|
|||
import { readChannelPermissions } from "../../../utils/readChannelPermissions";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
import { autoReactionsEvt } from "../types";
|
||||
import { AutoReaction } from "../../../data/entities/AutoReaction";
|
||||
|
||||
const p = Permissions.FLAGS;
|
||||
|
||||
|
@ -15,8 +16,19 @@ export const AddReactionsEvt = autoReactionsEvt({
|
|||
allowSelf: true,
|
||||
|
||||
async listener({ pluginData, args: { message } }) {
|
||||
const autoReaction = await pluginData.state.autoReactions.getForChannel(message.channel.id);
|
||||
if (!autoReaction) return;
|
||||
let autoReaction: AutoReaction | null = null;
|
||||
const lock = await pluginData.locks.acquire(`auto-reactions-${message.channel.id}`);
|
||||
if (pluginData.state.cache.has(message.channel.id)) {
|
||||
autoReaction = pluginData.state.cache.get(message.channel.id) ?? null;
|
||||
} else {
|
||||
autoReaction = (await pluginData.state.autoReactions.getForChannel(message.channel.id)) ?? null;
|
||||
pluginData.state.cache.set(message.channel.id, autoReaction);
|
||||
}
|
||||
lock.unlock();
|
||||
|
||||
if (!autoReaction) {
|
||||
return;
|
||||
}
|
||||
|
||||
const me = pluginData.guild.members.cache.get(pluginData.client.user!.id)!;
|
||||
if (me) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue