From: Tyler Anthony Romeo Date: Mon, 8 Oct 2012 03:47:46 +0000 (-0400) Subject: (bug 39490) Add caching to InfoAction. X-Git-Tag: 1.31.0-rc.0~21266^2 X-Git-Url: http://git.cyclocoop.org/%22%2C%20generer_url_ecrire%28?a=commitdiff_plain;h=4f71793786fe5c14752bb1f61f493c3d76e2018a;p=lhc%2Fweb%2Fwiklou.git (bug 39490) Add caching to InfoAction. Added caching to InfoAction. The cache key uses the ID of the latest revision so it is auto-invalidated when the page is changed. Also, the cache key is deleted whenever the page is purged. Change-Id: I90446b7bcb4517959605aa38eacfada2b785060b --- diff --git a/includes/Title.php b/includes/Title.php index 896218be29..bdaa66f864 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -4461,6 +4461,7 @@ class Title { * @return Bool true if the update succeded */ public function invalidateCache() { + global $wgMemc; if ( wfReadOnly() ) { return false; } @@ -4472,6 +4473,14 @@ class Title { __METHOD__ ); HTMLFileCache::clearFileCache( $this ); + + // Clear page info. + $revision = WikiPage::factory( $this )->getRevision(); + if( $revision !== null ) { + $memcKey = wfMemcKey( 'infoaction', $this->getPrefixedText(), $revision->getId() ); + $success = $success && $wgMemc->delete( $memcKey ); + } + return $success; } diff --git a/includes/actions/InfoAction.php b/includes/actions/InfoAction.php index 29c3d7e35a..fb8aea6f81 100644 --- a/includes/actions/InfoAction.php +++ b/includes/actions/InfoAction.php @@ -165,15 +165,21 @@ class InfoAction extends FormlessAction { * @return array */ protected function pageInfo() { - global $wgContLang, $wgRCMaxAge; + global $wgContLang, $wgRCMaxAge, $wgMemc; $user = $this->getUser(); $lang = $this->getLanguage(); $title = $this->getTitle(); $id = $title->getArticleID(); - // Get page information that would be too "expensive" to retrieve by normal means - $pageCounts = self::pageCounts( $title, $user ); + $memcKey = wfMemcKey( 'infoaction', $title->getPrefixedText(), $this->page->getRevision()->getId() ); + $pageCounts = $wgMemc->get( $memcKey ); + if ( $pageCounts === false ) { + // Get page information that would be too "expensive" to retrieve by normal means + $pageCounts = self::pageCounts( $title ); + + $wgMemc->set( $memcKey, $pageCounts ); + } // Get page properties $dbr = wfGetDB( DB_SLAVE ); @@ -259,7 +265,7 @@ class InfoAction extends FormlessAction { ); } - if ( isset( $pageCounts['watchers'] ) ) { + if ( $user->isAllowed( 'unwatchedpages' ) ) { // Number of page watchers $pageInfo['header-basic'][] = array( $this->msg( 'pageinfo-watchers' ), $lang->formatNum( $pageCounts['watchers'] ) @@ -473,11 +479,10 @@ class InfoAction extends FormlessAction { /** * Returns page counts that would be too "expensive" to retrieve by normal means. * - * @param $title Title object - * @param $user User object + * @param Title $title Title to get counts for * @return array */ - protected static function pageCounts( $title, $user ) { + protected static function pageCounts( Title $title ) { global $wgRCMaxAge, $wgDisableCounters; wfProfileIn( __METHOD__ ); @@ -497,19 +502,17 @@ class InfoAction extends FormlessAction { $result['views'] = $views; } - if ( $user->isAllowed( 'unwatchedpages' ) ) { - // Number of page watchers - $watchers = (int) $dbr->selectField( - 'watchlist', - 'COUNT(*)', - array( - 'wl_namespace' => $title->getNamespace(), - 'wl_title' => $title->getDBkey(), - ), - __METHOD__ - ); - $result['watchers'] = $watchers; - } + // Number of page watchers + $watchers = (int) $dbr->selectField( + 'watchlist', + 'COUNT(*)', + array( + 'wl_namespace' => $title->getNamespace(), + 'wl_title' => $title->getDBkey(), + ), + __METHOD__ + ); + $result['watchers'] = $watchers; // Total number of edits $edits = (int) $dbr->selectField(