@@ -239,13 +239,7 @@ private function saveRemediations(array $decisions): bool
239
239
}
240
240
}
241
241
}
242
-
243
- $ warmedUp = $ this ->adapter ->commit ();
244
-
245
- // Store the fact that the cache has been warmed up.
246
- $ this ->defferUpdateCacheConfig (['warmed_up ' => $ warmedUp ]);
247
-
248
- return $ warmedUp ;
242
+ return $ this ->adapter ->commit ();
249
243
}
250
244
251
245
private function removeRemediations (array $ decisions ): bool
@@ -263,7 +257,7 @@ private function removeRemediations(array $decisions): bool
263
257
if (!$ success ) {
264
258
// The API may return stale deletion events due to API design.
265
259
// Ignoring them is therefore not a problem.
266
- $ this ->logger ->debug ("Decision " . $ decision ['id ' ] . " not found in cache for one or more items. " );
260
+ $ this ->logger ->debug ("Decision " . $ decision ['id ' ] . " not found in cache for one or more items " );
267
261
}
268
262
}
269
263
}
@@ -297,7 +291,10 @@ private function saveRemediationsForIp(array $decisions, string $ip): string
297
291
298
292
public function clear (): bool
299
293
{
300
- return $ this ->adapter ->clear ();
294
+ $ cleared = $ this ->adapter ->clear ();
295
+ $ this ->warmedUp = false ;
296
+ $ this ->logger ->info ("Cache cleared " );
297
+ return $ cleared ;
301
298
}
302
299
303
300
/**
@@ -306,20 +303,27 @@ public function clear(): bool
306
303
* Used when the stream mode has just been activated.
307
304
*
308
305
*/
309
- private function warmUp (): void
306
+ public function warmUp (): void
310
307
{
311
- $ this ->logger ->info ('Warming the cache up ' );
308
+ $ this ->logger ->debug ('Warming the cache up ' );
312
309
$ startup = true ;
313
310
$ decisionsDiff = $ this ->apiClient ->getStreamedDecisions ($ startup );
314
311
$ newDecisions = $ decisionsDiff ['new ' ];
315
312
313
+ $ nbNew = 0 ;
316
314
if ($ newDecisions ) {
317
315
$ this ->warmedUp = $ this ->saveRemediations ($ newDecisions );
318
316
if (!$ this ->warmedUp ) {
319
317
throw new BouncerException ("Unable to warm the cache up " );
320
318
}
319
+ $ nbNew = count ($ newDecisions );
321
320
}
322
- $ this ->logger ->debug ('Cache warmed up ' );
321
+
322
+ // Store the fact that the cache has been warmed up.
323
+ $ this ->logger ->info ("Cache warmed up with $ nbNew decision(s) " );
324
+ $ this ->defferUpdateCacheConfig (['warmed_up ' => true ]);
325
+ $ this ->adapter ->commit ();
326
+
323
327
}
324
328
325
329
/**
@@ -331,26 +335,30 @@ private function warmUp(): void
331
335
*/
332
336
public function pullUpdates (): void
333
337
{
334
- $ this ->logger ->info ('Pulling updates from API ' );
335
338
if (!$ this ->warmedUp ) {
336
339
$ this ->warmUp ();
340
+ return ;
337
341
}
338
342
343
+ $ this ->logger ->debug ('Pulling updates from API ' );
339
344
$ decisionsDiff = $ this ->apiClient ->getStreamedDecisions ();
340
345
$ newDecisions = $ decisionsDiff ['new ' ];
341
346
$ deletedDecisions = $ decisionsDiff ['deleted ' ];
342
347
348
+ $ nbDeleted = 0 ;
343
349
if ($ deletedDecisions ) {
344
350
$ this ->removeRemediations ($ deletedDecisions );
351
+ $ nbDeleted = count ($ deletedDecisions );
345
352
}
346
-
353
+
354
+ $ nbNew = 0 ;
347
355
if ($ newDecisions ) {
348
356
$ this ->saveRemediations ($ newDecisions );
349
- if (!$ this ->warmedUp ) {
350
- throw new BouncerException ("Unable to warm the cache up " );
351
- }
357
+ $ nbNew = count ($ newDecisions );
352
358
}
353
- $ this ->logger ->debug ('Updates pulled from API ' );
359
+
360
+
361
+ $ this ->logger ->info ("Updates pulled from API (- $ nbDeleted+ $ nbNew) " );
354
362
}
355
363
356
364
/**
0 commit comments