Avoid revision lookup post-save in InfoAction::invalidateCache()
authorKunal Mehta <legoktm@gmail.com>
Wed, 29 Jul 2015 07:42:56 +0000 (00:42 -0700)
committerKunal Mehta <legoktm@gmail.com>
Wed, 29 Jul 2015 07:42:56 +0000 (00:42 -0700)
We just saved the page, so we know the revision id. Pass it on to
InfoAction::invalidateCache() so it doesn't have to be looked up again.

Follows-up 0452855044d2d.

Change-Id: I990c0da09fae94f403f3550069036d3f208090a6

includes/actions/InfoAction.php
includes/page/WikiPage.php

index 5491f81..f3670a8 100644 (file)
@@ -62,13 +62,17 @@ class InfoAction extends FormlessAction {
         *
         * @since 1.22
         * @param Title $title Title to clear cache for
+        * @param int|null $revid Revision id to clear
         */
-       public static function invalidateCache( Title $title ) {
+       public static function invalidateCache( Title $title, $revid = null ) {
                $cache = ObjectCache::getMainWANInstance();
 
-               $revision = Revision::newFromTitle( $title, 0, Revision::READ_LATEST );
-               if ( $revision !== null ) {
-                       $key = wfMemcKey( 'infoaction', sha1( $title->getPrefixedText() ), $revision->getId() );
+               if ( !$revid ) {
+                       $revision = Revision::newFromTitle( $title, 0, Revision::READ_LATEST );
+                       $revid = $revision ? $revision->getId() : null;
+               }
+               if ( $revid !== null ) {
+                       $key = wfMemcKey( 'infoaction', sha1( $title->getPrefixedText() ), $revid );
                        $cache->delete( $key );
                }
        }
index 4d4cb03..ae28cb8 100644 (file)
@@ -2257,7 +2257,7 @@ class WikiPage implements Page, IDBAccessObject {
                if ( $options['created'] ) {
                        self::onArticleCreate( $this->mTitle );
                } elseif ( $options['changed'] ) { // bug 50785
-                       self::onArticleEdit( $this->mTitle );
+                       self::onArticleEdit( $this->mTitle, $revision );
                }
        }
 
@@ -3213,8 +3213,9 @@ class WikiPage implements Page, IDBAccessObject {
         * Purge caches on page update etc
         *
         * @param Title $title
+        * @param Revision|null $revision Revision that was just saved, may be null
         */
-       public static function onArticleEdit( Title $title ) {
+       public static function onArticleEdit( Title $title, Revision $revision = null ) {
                // Invalidate caches of articles which include this page
                DeferredUpdates::addHTMLCacheUpdate( $title, 'templatelinks' );
 
@@ -3224,10 +3225,11 @@ class WikiPage implements Page, IDBAccessObject {
                // Purge squid for this page only
                $title->purgeSquid();
 
+               $revid = $revision ? $revision->getId() : null;
                // Clear file cache for this page only
                HTMLFileCache::clearFileCache( $title );
-               DeferredUpdates::addCallableUpdate( function() use ( $title ) {
-                       InfoAction::invalidateCache( $title );
+               DeferredUpdates::addCallableUpdate( function() use ( $title, $revid ) {
+                       InfoAction::invalidateCache( $title, $revid );
                } );
        }