From 0991572eff34f7a29192a731a66660d61edb8852 Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 6 Jul 2024 16:58:48 +0100 Subject: [PATCH] Further improvements to bot caching --- project/src/controllers/BotController.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/project/src/controllers/BotController.ts b/project/src/controllers/BotController.ts index 73d4e61d..53b5dcd4 100644 --- a/project/src/controllers/BotController.ts +++ b/project/src/controllers/BotController.ts @@ -329,14 +329,16 @@ export class BotController // Get number of bots we have in cache const botCacheCount = this.botGenerationCacheService.getCachedBotCount(cacheKey); const botPromises: Promise[] = []; - if (botCacheCount < botGenerationDetails.botCountToGenerate) + if (botCacheCount > botGenerationDetails.botCountToGenerate) { - // We're below desired count, add bots to cache - for (let i = 0; i < botGenerationDetails.botCountToGenerate; i++) - { - const detailsClone = this.cloner.clone(botGenerationDetails); - botPromises.push(this.generateSingleBotAndStoreInCache(detailsClone, sessionId, cacheKey)); - } + return; + } + + // We're below desired count, add bots to cache + for (let i = 0; i < botGenerationDetails.botCountToGenerate; i++) + { + const detailsClone = this.cloner.clone(botGenerationDetails); + botPromises.push(this.generateSingleBotAndStoreInCache(detailsClone, sessionId, cacheKey)); } return Promise.all(botPromises).then(() =>