Aaron Schulz has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/392993 )
Change subject: Add explicit cache purging via per-bucket check keys ...................................................................... Add explicit cache purging via per-bucket check keys If an override is revoked, then it will immediately affect relevant users. This restores the behavior as it was before 7c83c1846. Change-Id: Iccea53831c72d5ec6e54e7c35a91f8d04ff0f305 --- M SpecialOverrideThrottle.php M ThrottleOverride.hooks.php 2 files changed, 33 insertions(+), 4 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ThrottleOverride refs/changes/93/392993/1 diff --git a/SpecialOverrideThrottle.php b/SpecialOverrideThrottle.php index 7599ece..dcc5be7 100644 --- a/SpecialOverrideThrottle.php +++ b/SpecialOverrideThrottle.php @@ -17,6 +17,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +use MediaWiki\MediaWikiServices; class SpecialOverrideThrottle extends FormSpecialPage { /** @var string Sanitized target IP address or range */ @@ -180,6 +181,8 @@ $logId = $logEntry->insert(); $logEntry->publish( $logId ); + list( $rangeStart, $rangeEnd ) = $parsedRange; + // Save the new exemption $dbw = wfGetDB( DB_MASTER ); $row = [ @@ -187,10 +190,14 @@ 'thr_expiry' => $dbw->encodeExpiry( $data['Expiry'] ), 'thr_reason' => $reason, 'thr_type' => $types, - 'thr_range_start' => $parsedRange[0], - 'thr_range_end' => $parsedRange[1], + 'thr_range_start' => $rangeStart, + 'thr_range_end' => $rangeEnd, ]; + // Purge the cache + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); + $cache->touchCheckKey( ThrottleOverrideHooks::getBucketKey( $cache, $rangeStart ) ); + // If there already is an exemption for that target AND the user already confirmed // to override it, update the db row. Otherwise insert a new row. if ( $data['Modify'] && $this->throttleId ) { diff --git a/ThrottleOverride.hooks.php b/ThrottleOverride.hooks.php index 54a9fc9..3fbb43f 100644 --- a/ThrottleOverride.hooks.php +++ b/ThrottleOverride.hooks.php @@ -62,7 +62,7 @@ $expiry = $cache->getWithSetCallback( $cache->makeKey( 'throttle_override', $action, $hexIp ), $cache::TTL_HOUR, - function ( $cValue, &$ttl, &$setOpts, $asOf ) use ( $hexIp, $action ) { + function ( $cValue, &$ttl, &$setOpts, $asOf ) use ( $ip, $hexIp, $action ) { $dbr = wfGetDB( DB_REPLICA ); $setOpts += Database::getCacheSetOptions( $dbr ); @@ -93,7 +93,10 @@ // If we return false the value will not be cached return ( $expiry === false ) ? self::NO_OVERRIDE : $expiry; - } + }, + [ + 'checkKeys' => [ self::getBucketKey( $cache, $ip ) ] + ] ); if ( $expiry === self::NO_OVERRIDE ) { @@ -124,6 +127,25 @@ } /** + * Get the cache bucket key for either: + * - a) The valid IP address of a user + * - b) A throttle override that happens to include the given valid IP address + * + * @param WANObjectCache $cache + * @param string $ip IP address + * @return string + */ + public static function getBucketKey( WANObjectCache $cache, $ip ) { + global $wgThrottleOverrideCIDRLimit; + // Split the address space into buckets such that any given user IP address + // or throttle override's IP range will fall into exactly one bucket. + $proto = IP::isIPv6( $ip ) ? 'IPv6' : 'IPv4'; + $bucket = IP::sanitizeRange( "$ip/{$wgThrottleOverrideCIDRLimit[$proto]}" ); + // Purge all cache for all IPs in this bucket + return $cache->makeKey( 'throttle-override', $bucket ); + } + + /** * Make SQL query conditions. * * @param \Wikimedia\Rdbms\Database $db Database -- To view, visit https://gerrit.wikimedia.org/r/392993 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iccea53831c72d5ec6e54e7c35a91f8d04ff0f305 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ThrottleOverride Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits