From 2af3ca9ff5d1452abf40697037c0a87e87e05e3b Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 14 Mar 2024 22:14:00 +0000 Subject: [PATCH] Fix issue with generating event bots not being cached under the correct name Dont get bot from cache after generating it. Its popping bot off end of array only to be discarded --- project/src/controllers/BotController.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/project/src/controllers/BotController.ts b/project/src/controllers/BotController.ts index 4c3dc14f..90b8ce6c 100644 --- a/project/src/controllers/BotController.ts +++ b/project/src/controllers/BotController.ts @@ -214,14 +214,13 @@ export class BotController } // Loop over and make x bots for this bot wave - let cacheKey = ""; + const cacheKey = `${ + botGenerationDetails.eventRole ?? botGenerationDetails.role + }${botGenerationDetails.botDifficulty}`; for (let i = 0; i < botGenerationDetails.botCountToGenerate; i++) { - const detailsClone = this.jsonUtil.clone(botGenerationDetails); - - cacheKey = `${detailsClone.role}${detailsClone.botDifficulty}`; - // Generate and add bot to cache + const detailsClone = this.jsonUtil.clone(botGenerationDetails); const botToCache = this.botGenerator.prepareAndGenerateBot(sessionId, detailsClone); this.botGenerationCacheService.storeBots(cacheKey, [botToCache]); } @@ -231,9 +230,6 @@ export class BotController botGenerationDetails.eventRole ?? "" }) ${botGenerationDetails.botDifficulty} bots`, ); - - // Get bot from cache, add to return array - const botToReturn = this.botGenerationCacheService.getBot(cacheKey); } return [];