jenkins-bot has submitted this change and it was merged. Change subject: Fix bogus stats where stashes counted as misses ......................................................................
Fix bogus stats where stashes counted as misses Also renew stash values if they will expire soon. Change-Id: I36771f5736f80546aac99409463293c7699fb5de --- M SpamBlacklist_body.php 1 file changed, 22 insertions(+), 9 deletions(-) Approvals: Krinkle: Looks good to me, approved jenkins-bot: Verified diff --git a/SpamBlacklist_body.php b/SpamBlacklist_body.php index 35ad323..137947a 100644 --- a/SpamBlacklist_body.php +++ b/SpamBlacklist_body.php @@ -7,6 +7,8 @@ use \MediaWiki\MediaWikiServices; class SpamBlacklist extends BaseBlacklist { + const STASH_TTL = 60; + const STASH_AGE_DYING = 30; /** * Changes to external links, for logging purposes @@ -45,10 +47,11 @@ * @param boolean $preventLog Whether to prevent logging of hits. Set to true when * the action is testing the links rather than attempting to save them * (e.g. the API spamblacklist action) + * @param string $mode Either 'check' or 'stash' * * @return string[]|bool Matched text(s) if the edit should not be allowed; false otherwise */ - function filter( array $links, Title $title = null, $preventLog = false ) { + function filter( array $links, Title $title = null, $preventLog = false, $mode = 'check' ) { $statsd = MediaWikiServices::getInstance()->getStatsdDataFactory(); $cache = ObjectCache::getLocalClusterInstance(); $key = $cache->makeKey( @@ -59,11 +62,19 @@ (string)$title ); // Skip blacklist checks if nothing matched during edit stashing... - if ( $cache->get( $key ) ) { - $statsd->increment( 'spamblacklist.check-stash.hit' ); - return false; - } else { - $statsd->increment( 'spamblacklist.check-stash.miss' ); + $knownNonMatchAsOf = $cache->get( $key ); + if ( $mode === 'check' ) { + if ( $knownNonMatchAsOf ) { + $statsd->increment( 'spamblacklist.check-stash.hit' ); + + return false; + } else { + $statsd->increment( 'spamblacklist.check-stash.miss' ); + } + } elseif ( $mode === 'stash' ) { + if ( $knownNonMatchAsOf && ( time() - $knownNonMatchAsOf ) < self::STASH_AGE_DYING ) { + return false; // OK; not about to expire soon + } } $blacklists = $this->getBlacklists(); @@ -143,8 +154,10 @@ if ( $retVal === false ) { // Cache the typical negative results - $cache->set( $key, 1, $cache::TTL_MINUTE ); - $statsd->increment( 'spamblacklist.check-stash.store' ); + $cache->set( $key, time(), $cache::TTL_MINUTE ); + if ( $mode === 'stash' ) { + $statsd->increment( 'spamblacklist.check-stash.store' ); + } } return $retVal; @@ -264,7 +277,7 @@ } public function warmCachesForFilter( Title $title, array $entries ) { - $this->filter( $entries, $title, true /* no logging */ ); + $this->filter( $entries, $title, true /* no logging */, 'stash' ); } /** -- To view, visit https://gerrit.wikimedia.org/r/307467 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I36771f5736f80546aac99409463293c7699fb5de Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/SpamBlacklist Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Victor Vasiliev <vasi...@mit.edu> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits