Skip to content

Commit ec06c90

Browse files
feat(cache): Change refresh message on admin and add end-to-end test for bad dsn
1 parent a950ed6 commit ec06c90

File tree

8 files changed

+393
-393
lines changed

8 files changed

+393
-393
lines changed

inc/admin/advanced-settings.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ function adminAdvancedSettings()
2323
$bouncer = new Bouncer($configs);
2424
$bouncer->clearCache();
2525
$refresh = $bouncer->refreshBlocklistCache();
26-
$result = $refresh['new']??0;
27-
$message = __('As the stream mode is enabled, the cache has just been refreshed, '.($result > 1 ? 'there are now '.$result.' decisions' : 'there is now '.$result.' decision').' in cache.');
26+
$new = $refresh['new']??0;
27+
$deleted = $refresh['deleted']??0;
28+
$message = __('As the stream mode is enabled, the cache has just been refreshed. New decision(s): '.$new.'. Deleted decision(s): '. $deleted);
2829
AdminNotice::displaySuccess($message);
2930
scheduleBlocklistRefresh();
3031
}, function () {
@@ -54,11 +55,9 @@ function adminAdvancedSettings()
5455
$bouncer = new Bouncer($configs);
5556
$bouncer->clearCache();
5657
$refresh = $bouncer->refreshBlocklistCache();
57-
$result = $refresh['new']??0;
58-
$message = __('As the stream mode refresh duration changed, the cache has just been refreshed, ' .
59-
($result > 1 ? 'there are now '.$result.' decisions' : 'there is now '.$result.' decision')
60-
. ' in cache.'
61-
);
58+
$new = $refresh['new']??0;
59+
$deleted = $refresh['deleted']??0;
60+
$message = __('As the stream mode refresh duration changed, the cache has just been refreshed. New decision(s): '.$new.'. Deleted decision(s): '. $deleted);
6261
AdminNotice::displaySuccess($message);
6362
scheduleBlocklistRefresh();
6463
}
@@ -170,8 +169,9 @@ function adminAdvancedSettings()
170169
// system
171170
$bouncer->clearCache();
172171
$result = $bouncer->refreshBlocklistCache();
173-
$count = $result['new'];
174-
$message .= __('As the stream mode is enabled, the cache has just been refreshed, '.($count > 1 ? 'there are now '.$count.' decisions' : 'there is now '.$count.' decision').' in cache.');
172+
$new = $result['new']??0;
173+
$deleted = $result['deleted']??0;
174+
$message = __('As the stream mode is enabled, the cache has just been refreshed. New decision(s): '.$new.'. Deleted decision(s): '. $deleted);
175175
AdminNotice::displaySuccess($message);
176176
scheduleBlocklistRefresh();
177177
}
@@ -350,7 +350,7 @@ function convertInlineIpRangesToComparableIpBounds(string $inlineIpRanges): arra
350350
return Constants::CACHE_EXPIRATION_FOR_GEO;
351351
}
352352

353-
return (int) $input >= 0 ? (int) $input : Constants::CACHE_EXPIRATION_FOR_CAPTCHA ;
353+
return (int) $input;
354354
}, ' seconds. <p>The lifetime of cached country geolocation result for some IP.<br>Default: '
355355
.Constants::CACHE_EXPIRATION_FOR_GEO.'.<br>Set 0 to disable caching', Constants::CACHE_EXPIRATION_FOR_GEO,
356356
'width: 115px;', 'number');

inc/admin/init.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ function clearBouncerCacheInAdminPage()
4545
// In stream mode, immediatelly warm the cache up.
4646
if (get_option('crowdsec_stream_mode')) {
4747
$refresh = $bouncer->refreshBlocklistCache();
48-
$result = $refresh['new']??0;
49-
$message .= __(' As the stream mode is enabled, the cache has just been refreshed, '.($result > 1 ? 'there are now '.$result.' decisions' : 'there is now '.$result.' decision').' in cache.');
48+
$new = $refresh['new']??0;
49+
$deleted = $refresh['deleted']??0;
50+
$message .= __(' As the stream mode is enabled, the cache has just been refreshed. New decision(s): '.$new.'. Deleted decision(s): '. $deleted);
5051
}
5152

5253
AdminNotice::displaySuccess($message);
@@ -77,7 +78,10 @@ function refreshBouncerCacheInAdminPage()
7778
$configs = getDatabaseConfigs();
7879
$bouncer = new Bouncer($configs);
7980
$result = $bouncer->refreshBlocklistCache();
80-
AdminNotice::displaySuccess(__(' The cache has just been refreshed ('.($result['new'] > 0 ? $result['new'].' new decisions' : $result['new'].' new decision').', '.$result['deleted'].' deleted).'));
81+
$new = $result['new']??0;
82+
$deleted = $result['deleted']??0;
83+
$message = __('The cache has just been refreshed. New decision(s): '.$new.'. Deleted decision(s): '. $deleted);
84+
AdminNotice::displaySuccess($message);
8185
}
8286
} catch (BouncerException $e) {
8387
if(isset($bouncer) && $bouncer->getLogger()) {

0 commit comments

Comments
 (0)