Skip to content

Commit 5b2bd32

Browse files
author
Chomp
committed
Only add bot to cache when it has a value
1 parent 4c953ea commit 5b2bd32

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

project/src/controllers/BotController.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -390,24 +390,26 @@ export class BotController {
390390
* @param request Bot generation request object
391391
* @returns An array of IBotBase objects as requested by request
392392
*/
393-
protected async returnBotsFromCache(
394-
request: IGenerateBotsRequestData,
395-
): Promise<IBotBase[]> {
393+
protected async returnBotsFromCache(request: IGenerateBotsRequestData): Promise<IBotBase[]> {
396394
const desiredBots: IBotBase[] = [];
397395

398396
// We can assume that during this call, we have enough bots cached to cover the request
399397
request.conditions.map((requestedBot) => {
400398
// Create a compound key to store bots in cache against
401-
const cacheKey = this.botGenerationCacheService.createCacheKey(
402-
requestedBot.Role,
403-
requestedBot.Difficulty,
404-
);
399+
const cacheKey = this.botGenerationCacheService.createCacheKey(requestedBot.Role, requestedBot.Difficulty);
405400

406401
// Fetch enough bots to satisfy the request
407-
for (let i = 0; i < requestedBot.Limit; i++)
408-
{
402+
for (let i = 0; i < requestedBot.Limit; i++) {
403+
// Pull bot out of generation cache
409404
const desiredBot = this.botGenerationCacheService.getBot(cacheKey);
405+
if (!desiredBot) {
406+
continue;
407+
}
408+
409+
// Store bot inside cache to be referenced after raid
410410
this.botGenerationCacheService.storeUsedBot(desiredBot);
411+
412+
// Add bot to returned array
411413
desiredBots.push(desiredBot);
412414
}
413415
});

0 commit comments

Comments
 (0)