jenkins-bot has submitted this change and it was merged. Change subject: Conversion to using WAN cache ......................................................................
Conversion to using WAN cache * Also removed some code duplication * Use getConnectionRef in checkAllFilters so that the DB connection can be reused Bug: T93141 Change-Id: I17c5a976b6c45029cde4ed34ad82d69e365ae8c5 --- M AbuseFilter.class.php M Views/AbuseFilterViewEdit.php 2 files changed, 30 insertions(+), 44 deletions(-) Approvals: Alex Monk: Looks good to me, approved jenkins-bot: Verified diff --git a/AbuseFilter.class.php b/AbuseFilter.class.php old mode 100644 new mode 100755 index e8df9d9..a83ead5 --- a/AbuseFilter.class.php +++ b/AbuseFilter.class.php @@ -434,6 +434,8 @@ * @return array */ public static function checkAllFilters( $vars, $group = 'default' ) { + global $wgAbuseFilterCentralDB, $wgAbuseFilterIsCentral; + // Fetch from the database. $filter_matched = array(); @@ -453,34 +455,36 @@ $filter_matched[$row->af_id] = self::checkFilter( $row, $vars, true ); } - global $wgAbuseFilterCentralDB, $wgAbuseFilterIsCentral, $wgMemc; - if ( $wgAbuseFilterCentralDB && !$wgAbuseFilterIsCentral ) { // Global filters $globalRulesKey = self::getGlobalRulesKey( $group ); - $memcacheRules = $wgMemc->get( $globalRulesKey ); - if ( $memcacheRules ) { - $res = $memcacheRules; - } else { - $fdb = wfGetDB( DB_SLAVE, array(), $wgAbuseFilterCentralDB ); - $res = $fdb->select( - 'abuse_filter', - '*', - array( - 'af_enabled' => 1, - 'af_deleted' => 0, - 'af_global' => 1, - 'af_group' => $group, - ), - __METHOD__ - ); - $memcacheRules = array(); - foreach ( $res as $row ) { - $memcacheRules[] = $row; - } - $wgMemc->set( $globalRulesKey, $memcacheRules ); - } + $fname = __METHOD__; + $res = ObjectCache::getMainWANInstance()->getWithSetCallback( + $globalRulesKey, + function() use ( $group, $fname ) { + global $wgAbuseFilterCentralDB; + + $fdb = wfGetLB( $wgAbuseFilterCentralDB )->getConnectionRef( + DB_SLAVE, array(), $wgAbuseFilterCentralDB + ); + + return iterator_to_array( $fdb->select( + 'abuse_filter', + '*', + array( + 'af_enabled' => 1, + 'af_deleted' => 0, + 'af_global' => 1, + 'af_group' => $group, + ), + $fname + ) ); + }, + 0, + array( $globalRulesKey ), + array( 'lockTSE' => 300 ) + ); foreach( $res as $row ) { $filter_matched['global-' . $row->af_id] = diff --git a/Views/AbuseFilterViewEdit.php b/Views/AbuseFilterViewEdit.php index 5ccdbbc..14dbce0 100755 --- a/Views/AbuseFilterViewEdit.php +++ b/Views/AbuseFilterViewEdit.php @@ -229,35 +229,17 @@ // Reset Memcache if this was a global rule if ( $newRow['af_global'] ) { - global $wgMemc; $group = 'default'; if ( isset( $newRow['af_group'] ) && $newRow['af_group'] != '' ) { $group = $newRow['af_group']; } - $memcacheRules = array(); - $res = $dbw->select( - 'abuse_filter', - '*', - array( - 'af_enabled' => 1, - 'af_deleted' => 0, - 'af_global' => 1, - 'af_group' => $group, - ), - __METHOD__ - ); - foreach ( $res as $row ) { - $memcacheRules[] = $row; - } - - $wgMemc->set( AbuseFilter::getGlobalRulesKey( $group ), $memcacheRules ); + $globalRulesKey = AbuseFilter::getGlobalRulesKey( $group ); + ObjectCache::getMainWANInstance()->touchCheckKey( $globalRulesKey ); } // Logging - $lp = new LogPage( 'abusefilter' ); - $lp->addEntry( 'modify', $this->getTitle( $new_id ), '', array( $history_id, $new_id ) ); // Purge the tag list cache so the fetchAllTags hook applies tag changes -- To view, visit https://gerrit.wikimedia.org/r/210647 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I17c5a976b6c45029cde4ed34ad82d69e365ae8c5 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/AbuseFilter Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Alex Monk <kren...@gmail.com> Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com> Gerrit-Reviewer: Se4598 <se4...@gmx.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits