Skip to content

Commit

Permalink
Optimizing cache updates in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
pdellaert committed Oct 27, 2024
1 parent 41077a5 commit 993766a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/commands/moderation/prefixCommands/prefixCommandCacheUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ export default slashCommand(data, async ({ interaction }) => {

const modLogsChannel = interaction.guild.channels.resolve(constantsConfig.channels.MOD_LOGS) as TextChannel;
const start = new Date().getTime();

await refreshAllPrefixCommandVersionsCache();
await refreshAllPrefixCommandCategoriesCache();
await refreshAllPrefixCommandsCache();
await refreshAllPrefixCommandChannelDefaultVersionsCache();
try {
await Promise.all([
refreshAllPrefixCommandVersionsCache(),
refreshAllPrefixCommandCategoriesCache(),
refreshAllPrefixCommandsCache(),
refreshAllPrefixCommandChannelDefaultVersionsCache(),
]);
} catch (error) {
await interaction.editReply({ content: `An error occurred while updating the cache: ${error}` });
return;
}

const duration = ((new Date().getTime() - start) / 1000).toFixed(2);

Expand Down
10 changes: 6 additions & 4 deletions src/lib/schedulerJobs/refreshInMemoryCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ export async function refreshInMemoryCache(job: Job) {

const start = new Date().getTime();
try {
await refreshAllPrefixCommandVersionsCache();
await refreshAllPrefixCommandCategoriesCache();
await refreshAllPrefixCommandsCache();
await refreshAllPrefixCommandChannelDefaultVersionsCache();
await Promise.all([
refreshAllPrefixCommandVersionsCache(),
refreshAllPrefixCommandCategoriesCache(),
refreshAllPrefixCommandsCache(),
refreshAllPrefixCommandChannelDefaultVersionsCache(),
]);
} catch (error) {
Logger.error('Failed to refresh the in memory cache:', error);
}
Expand Down

0 comments on commit 993766a

Please sign in to comment.