Skip to content

Commit

Permalink
redis caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Larsundso committed Jan 6, 2025
1 parent 13ba8d7 commit 5227495
Show file tree
Hide file tree
Showing 3 changed files with 350 additions and 31 deletions.
5 changes: 3 additions & 2 deletions src/BaseClient/Bot/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ const client = new Discord.Client({
});

client.cluster = new Sharding.ClusterClient(client);
await client.login(

const login = client.login(
(process.argv.includes('--dev') ? process.env.DevToken : process.env.Token) ?? '',
);

middleware(client);
await login;

export const API = new DiscordCore.API(client.rest);
export default client;
6 changes: 3 additions & 3 deletions src/BaseClient/Bot/DataBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ export const cacheNewEntry = <T extends keyof DataBaseTables>(
res
.filter((r) => !!r[keyName])
.forEach((r) =>
Redis.set(`${process.env.mainId}:${tableName}:${r[keyName]}`, JSON.stringify(r)),
Redis.set(`${process.env.mainId}:settings:${tableName}:${r[keyName]}`, JSON.stringify(r)),
);
} else if (res[keyName]) {
Redis.set(`${process.env.mainId}:${tableName}:${res[keyName]}`, JSON.stringify(res));
Redis.set(`${process.env.mainId}:settings:${tableName}:${res[keyName]}`, JSON.stringify(res));
}

return res;
Expand Down Expand Up @@ -194,7 +194,7 @@ export const handleOperation = <T extends keyof Prisma.TypeMap['model'] & keyof
const indexValues = getKey<typeof name>(data.args.where, index);

if (!indexValues?.length) return data.query(data.args);
const keys = indexValues.map((value) => `${process.env.mainId}:${name}:${value}`);
const keys = indexValues.map((value) => `${process.env.mainId}:settings:${name}:${value}`);

switch (data.operation) {
case 'findMany':
Expand Down
Loading

0 comments on commit 5227495

Please sign in to comment.