Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/271683

Change subject: Pre-cache the link list for external link filters
......................................................................

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
(cherry picked from commit 2acfb30bfcd0e121b4f7d0e0a75d628e80588f03)
---
M BaseBlacklist.php
M SpamBlacklistHooks.php
M SpamBlacklist_body.php
M extension.json
4 files changed, 37 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SpamBlacklist 
refs/changes/83/271683/1

diff --git a/BaseBlacklist.php b/BaseBlacklist.php
index 2d563d7..998ffa2 100755
--- a/BaseBlacklist.php
+++ b/BaseBlacklist.php
@@ -407,4 +407,11 @@
        public function getRegexEnd( $batchSize ) {
                return ($batchSize > 0 ) ? '/Sim' : '/im';
        }
+
+       /**
+        * @param $title Title
+        */
+       public function warmCachesForFilter( Title $title ) {
+               // subclass this
+       }
 }
diff --git a/SpamBlacklistHooks.php b/SpamBlacklistHooks.php
index 45942ea..84810bf 100755
--- a/SpamBlacklistHooks.php
+++ b/SpamBlacklistHooks.php
@@ -77,6 +77,11 @@
                return true;
        }
 
+       public static function onParserOutputStashForEdit( WikiPage $page ) {
+               $spamObj = BaseBlacklist::getInstance( 'spam' );
+               $spamObj->warmCachesForFilter( $page->getTitle() );
+       }
+
        /**
         * Hook function for APIEditBeforeSave.
         * This allows blacklist matches to be reported directly in the result 
structure
diff --git a/SpamBlacklist_body.php b/SpamBlacklist_body.php
index 8c270f4..51113ff 100644
--- a/SpamBlacklist_body.php
+++ b/SpamBlacklist_body.php
@@ -123,16 +123,28 @@
         * @param $title Title
         * @return array
         */
-       function getCurrentLinks( $title ) {
-               $dbr = wfGetDB( DB_SLAVE );
-               $id = $title->getArticleID(); // should be zero queries
-               $res = $dbr->select( 'externallinks', array( 'el_to' ),
-                       array( 'el_from' => $id ), __METHOD__ );
-               $links = array();
-               foreach ( $res as $row ) {
-                       $links[] = $row->el_to;
-               }
-               return $links;
+       function getCurrentLinks( Title $title ) {
+               $cache = ObjectCache::getMainWANInstance();
+               return $cache->getWithSetCallback(
+                       // Key is warmed via warmCachesForFilter() from 
ApiStashEdit
+                       $cache->makeKey( 'external-link-list', 
$title->getLatestRevID() ),
+                       $cache::TTL_MINUTE,
+                       function ( $oldValue, &$ttl, array &$setOpts ) use ( 
$title ) {
+                               $dbr = wfGetDB( DB_SLAVE );
+                               $setOpts += Database::getCacheSetOptions( $dbr 
);
+
+                               return $dbr->selectFieldValues(
+                                       'externallinks',
+                                       'el_to',
+                                       array( 'el_from' => 
$title->getArticleID() ), // should be zero queries
+                                       __METHOD__
+                               );
+                       }
+               );
+       }
+
+       public function warmCachesForFilter( Title $title ) {
+               $this->getCurrentLinks( $title );
        }
 
        /**
diff --git a/extension.json b/extension.json
index 4afcab4..3cf605d 100644
--- a/extension.json
+++ b/extension.json
@@ -64,6 +64,9 @@
                ],
                "AbortNewAccount": [
                        "SpamBlacklistHooks::abortNewAccount"
+               ],
+               "ParserOutputStashForEdit": [
+                       "SpamBlacklistHooks::onParserOutputStashForEdit"
                ]
        },
        "config": {

-- 
To view, visit https://gerrit.wikimedia.org/r/271683
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0ad5289324b5482db7e2276f58fc1ac140250d47
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SpamBlacklist
Gerrit-Branch: wmf/1.27.0-wmf.14
Gerrit-Owner: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to