Ori.livneh has uploaded a new change for review.

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

Change subject: Improve edit stash hit rate for logged-out users
......................................................................

Improve edit stash hit rate for logged-out users

Check whether they made intervening edits just like logged-in users.

Bug: T134620
Change-Id: Id1e0808caee0e474570c4f2e4b1cf845572e17e0
(cherry picked from commit ba6844e21c67158c268926c3ffe6ef6214eb3668)
---
M includes/api/ApiStashEdit.php
1 file changed, 26 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/10/289310/1

diff --git a/includes/api/ApiStashEdit.php b/includes/api/ApiStashEdit.php
index 3539eed..93003cc 100644
--- a/includes/api/ApiStashEdit.php
+++ b/includes/api/ApiStashEdit.php
@@ -294,9 +294,17 @@
                        $logger->debug( "Timestamp-based cache hit for key 
'$key' (age: $age sec)." );
                        return $editInfo; // assume nothing changed
                } elseif ( isset( $editInfo->edits ) && $editInfo->edits === 
$user->getEditCount() ) {
+                       // Logged-in user made no local upload/template edits 
in the meantime
                        $stats->increment( 
'editstash.cache_hits.presumed_fresh' );
                        $logger->debug( "Edit count based cache hit for key 
'$key' (age: $age sec)." );
-                       return $editInfo; // use made no local upload/template 
edits in the meantime
+                       return $editInfo;
+               } elseif ( $user->isAnon()
+                       && self::lastEditTime( $user ) < 
$editInfo->output->getCacheTime()
+               ) {
+                       // Logged-out user made no local upload/template edits 
in the meantime
+                       $stats->increment( 
'editstash.cache_hits.presumed_fresh' );
+                       $logger->debug( "Edit check based cache hit for key 
'$key' (age: $age sec)." );
+                       return $editInfo;
                }
 
                $dbr = wfGetDB( DB_SLAVE );
@@ -360,6 +368,21 @@
        }
 
        /**
+        * @param User $user
+        * @return string|null TS_MW timestamp or null
+        */
+       private static function lastEditTime( User $user ) {
+               $time = wfGetDB( DB_SLAVE )->selectField(
+                       'recentchanges',
+                       'MAX(rc_timestamp)',
+                       [ 'rc_user_text' => $user->getName() ],
+                       __METHOD__
+               );
+
+               return wfTimestampOrNull( TS_MW, $time );
+       }
+
+       /**
         * Get the temporary prepared edit stash key for a user
         *
         * This key can be used for caching prepared edits provided:
@@ -371,7 +394,7 @@
         * @param User $user User to get parser options from
         * @return string
         */
-       protected static function getStashKey( Title $title, Content $content, 
User $user ) {
+       private static function getStashKey( Title $title, Content $content, 
User $user ) {
                $hash = sha1( implode( ':', [
                        $content->getModel(),
                        $content->getDefaultFormat(),
@@ -394,7 +417,7 @@
         * @param User $user
         * @return array (stash info array, TTL in seconds) or (null, 0)
         */
-       protected static function buildStashValue(
+       private static function buildStashValue(
                Content $pstContent, ParserOutput $parserOutput, $timestamp, 
User $user
        ) {
                // If an item is renewed, mind the cache TTL determined by 
config and parser functions.

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id1e0808caee0e474570c4f2e4b1cf845572e17e0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.28.0-wmf.2
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