mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/SpamBlacklist
synced 2024-11-23 22:54:57 +00:00
Pre-cache the link list for external link filters
* This works via plugging into ApiStashEdit. * The query is relatively slow per performance.wikimedia.org/xenon/svgs/daily/2016-02-15.index.svgz. Change-Id: I0ad5289324b5482db7e2276f58fc1ac140250d47
This commit is contained in:
parent
81727140ba
commit
2acfb30bfc
|
@ -407,4 +407,11 @@ abstract class BaseBlacklist {
|
||||||
public function getRegexEnd( $batchSize ) {
|
public function getRegexEnd( $batchSize ) {
|
||||||
return ($batchSize > 0 ) ? '/Sim' : '/im';
|
return ($batchSize > 0 ) ? '/Sim' : '/im';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $title Title
|
||||||
|
*/
|
||||||
|
public function warmCachesForFilter( Title $title ) {
|
||||||
|
// subclass this
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,11 @@ class SpamBlacklistHooks {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function onParserOutputStashForEdit( WikiPage $page ) {
|
||||||
|
$spamObj = BaseBlacklist::getInstance( 'spam' );
|
||||||
|
$spamObj->warmCachesForFilter( $page->getTitle() );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook function for APIEditBeforeSave.
|
* Hook function for APIEditBeforeSave.
|
||||||
* This allows blacklist matches to be reported directly in the result structure
|
* This allows blacklist matches to be reported directly in the result structure
|
||||||
|
|
|
@ -123,16 +123,28 @@ class SpamBlacklist extends BaseBlacklist {
|
||||||
* @param $title Title
|
* @param $title Title
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function getCurrentLinks( $title ) {
|
function getCurrentLinks( Title $title ) {
|
||||||
$dbr = wfGetDB( DB_SLAVE );
|
$cache = ObjectCache::getMainWANInstance();
|
||||||
$id = $title->getArticleID(); // should be zero queries
|
return $cache->getWithSetCallback(
|
||||||
$res = $dbr->select( 'externallinks', array( 'el_to' ),
|
// Key is warmed via warmCachesForFilter() from ApiStashEdit
|
||||||
array( 'el_from' => $id ), __METHOD__ );
|
$cache->makeKey( 'external-link-list', $title->getLatestRevID() ),
|
||||||
$links = array();
|
$cache::TTL_MINUTE,
|
||||||
foreach ( $res as $row ) {
|
function ( $oldValue, &$ttl, array &$setOpts ) use ( $title ) {
|
||||||
$links[] = $row->el_to;
|
$dbr = wfGetDB( DB_SLAVE );
|
||||||
}
|
$setOpts += Database::getCacheSetOptions( $dbr );
|
||||||
return $links;
|
|
||||||
|
return $dbr->selectFieldValues(
|
||||||
|
'externallinks',
|
||||||
|
'el_to',
|
||||||
|
array( 'el_from' => $title->getArticleID() ), // should be zero queries
|
||||||
|
__METHOD__
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function warmCachesForFilter( Title $title ) {
|
||||||
|
$this->getCurrentLinks( $title );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -64,6 +64,9 @@
|
||||||
],
|
],
|
||||||
"AbortNewAccount": [
|
"AbortNewAccount": [
|
||||||
"SpamBlacklistHooks::abortNewAccount"
|
"SpamBlacklistHooks::abortNewAccount"
|
||||||
|
],
|
||||||
|
"ParserOutputStashForEdit": [
|
||||||
|
"SpamBlacklistHooks::onParserOutputStashForEdit"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
|
|
Loading…
Reference in a new issue