From b795a6e51b9ff69ed958f985908f81aff73022dc Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Tue, 20 Jul 2021 16:35:27 -0400 Subject: fixed caching --- src/tasks/updateCache.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/tasks') diff --git a/src/tasks/updateCache.ts b/src/tasks/updateCache.ts index cfadeb5..1a17aef 100644 --- a/src/tasks/updateCache.ts +++ b/src/tasks/updateCache.ts @@ -1,6 +1,7 @@ import { BushClient } from '../lib/extensions/discord-akairo/BushClient'; import { BushTask } from '../lib/extensions/discord-akairo/BushTask'; import { Global } from '../lib/models/Global'; +import { Guild } from '../lib/models/Guild'; import config from './../config/options'; export class UpdateCacheTask extends BushTask { @@ -12,19 +13,19 @@ export class UpdateCacheTask extends BushTask { } public async exec(): Promise { await UpdateCacheTask.updateGlobalCache(this.client); - // await UpdateCacheTask.updateGuildCache(this.client); + await UpdateCacheTask.updateGuildCache(this.client); await this.client.logger.verbose(`UpdateCache`, `Updated cache.`); } public static async init(client: BushClient): Promise { await UpdateCacheTask.updateGlobalCache(client); - // await UpdateCacheTask.updateGuildCache(client); + await UpdateCacheTask.updateGuildCache(client); } private static async updateGlobalCache(client: BushClient): Promise { const environment = config.environment; const row = - (await Global.findByPk(environment)) || + ((await Global.findByPk(environment)) || (await Global.create({ environment, superUsers: [], @@ -32,14 +33,17 @@ export class UpdateCacheTask extends BushTask { blacklistedGuilds: [], blacklistedUsers: [], disabledCommands: [] - })); + }))).toJSON() for (const option in row) { - if (client.cache[option]) client.cache[option] = row[option]; + if (Object.keys(client.cache.global).includes(option)) client.cache.global[option] = row[option]; } } private static async updateGuildCache(client: BushClient): Promise { - // client.db.query(`SELECT * FROM 'Guilds'`) + const rows = await Guild.findAll(); + for (const row of rows){ + client.cache.guilds.set(row.id, row.toJSON() as Guild) + } } } -- cgit