@@ -156,8 +156,7 @@ export class BotController {
156
156
const pmcProfile = this . profileHelper . getPmcProfile ( sessionId ) ;
157
157
158
158
// If we don't have enough bots cached to satisfy this request, populate the cache
159
- if ( ! this . cacheSatisfiesRequest ( info ) )
160
- {
159
+ if ( ! this . cacheSatisfiesRequest ( info ) ) {
161
160
await this . generateAndCacheBots ( info , pmcProfile , sessionId ) ;
162
161
}
163
162
@@ -166,16 +165,13 @@ export class BotController {
166
165
167
166
/**
168
167
* Return true if the current cache satisfies the passed in bot generation request
169
- * @param info
170
- * @returns
168
+ * @param info
169
+ * @returns
171
170
*/
172
171
public cacheSatisfiesRequest ( info : IGenerateBotsRequestData ) : boolean {
173
172
return info . conditions . every ( ( condition ) => {
174
173
// Create the key that would be used for caching this bot type, so we can check how many exist
175
- const cacheKey = this . botGenerationCacheService . createCacheKey (
176
- condition . Role ,
177
- condition . Difficulty
178
- ) ;
174
+ const cacheKey = this . botGenerationCacheService . createCacheKey ( condition . Role , condition . Difficulty ) ;
179
175
180
176
return this . botGenerationCacheService . getCachedBotCount ( cacheKey ) >= condition . Limit ;
181
177
} ) ;
@@ -202,13 +198,9 @@ export class BotController {
202
198
// Map conditions to promises for bot generation
203
199
const conditionPromises = request . conditions . map ( async ( condition ) => {
204
200
// If we already have enough for this bot type, don't generate more
205
- const cacheKey = this . botGenerationCacheService . createCacheKey (
206
- condition . Role ,
207
- condition . Difficulty
208
- ) ;
201
+ const cacheKey = this . botGenerationCacheService . createCacheKey ( condition . Role , condition . Difficulty ) ;
209
202
210
- if ( this . botGenerationCacheService . getCachedBotCount ( cacheKey ) >= condition . Limit )
211
- {
203
+ if ( this . botGenerationCacheService . getCachedBotCount ( cacheKey ) >= condition . Limit ) {
212
204
return ;
213
205
}
214
206
@@ -327,7 +319,7 @@ export class BotController {
327
319
// Get number of bots we have in cache
328
320
const botCacheCount = this . botGenerationCacheService . getCachedBotCount ( cacheKey ) ;
329
321
330
- if ( botCacheCount >= botGenerationDetails . botCountToGenerate ) {
322
+ if ( botCacheCount > botGenerationDetails . botCountToGenerate ) {
331
323
this . logger . debug ( `Cache already has sufficient ${ cacheKey } bots: ${ botCacheCount } , skipping generation` ) ;
332
324
return ;
333
325
}
0 commit comments