Add cache helper to update user cache every 30 minutes
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
808f5e3b1c
commit
5f054b02a5
15 changed files with 85 additions and 2 deletions
27
src/helpers/CacheHelper.ts
Normal file
27
src/helpers/CacheHelper.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { Guild } from "discord.js";
|
||||
import Server from "../database/entities/Server";
|
||||
|
||||
export default class CacheHelper {
|
||||
public static async UpdateServerCache(guild: Guild) {
|
||||
const cacheInterval = process.env.CACHE_INTERVAL;
|
||||
|
||||
if (!cacheInterval) return;
|
||||
|
||||
let server = await Server.FetchOneById(Server, guild.id);
|
||||
|
||||
if (!server) {
|
||||
server = new Server(guild.id);
|
||||
await server.Save(Server, server);
|
||||
|
||||
await CacheHelper.UpdateCache(guild);
|
||||
} else if (server.LastCached.getTime() + Number(cacheInterval) < Date.now()) {
|
||||
await CacheHelper.UpdateCache(guild);
|
||||
}
|
||||
}
|
||||
|
||||
private static async UpdateCache(guild: Guild) {
|
||||
console.log(`Updating cache for ${guild.name} (${guild.id})`);
|
||||
|
||||
await guild.members.fetch();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue