From b84d573d4bcb714b41b371eeaa1cf6666f42b8c9 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 6 Apr 2015 11:12:41 -0700 Subject: [PATCH] Made User::newTouchedTimestamp handle clock skew a bit better * This does not handle race conditions, but is a prelude to using CAS style logic on save using the timestamp. Change-Id: I9c31c272fcf77b686764b7c3a6a32ac29576347c --- includes/User.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/includes/User.php b/includes/User.php index 322f8af5ec..6ac320e795 100644 --- a/includes/User.php +++ b/includes/User.php @@ -2233,9 +2233,15 @@ class User implements IDBAccessObject { * user_touched field when we update things. * @return string Timestamp in TS_MW format */ - private static function newTouchedTimestamp() { + private function newTouchedTimestamp() { global $wgClockSkewFudge; - return wfTimestamp( TS_MW, time() + $wgClockSkewFudge ); + + $time = wfTimestamp( TS_MW, time() + $wgClockSkewFudge ); + if ( $this->mTouched && $time <= $this->mTouched ) { + $time = wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, $this->mTouched ) + 1 ); + } + + return $time; } /** @@ -2265,7 +2271,7 @@ class User implements IDBAccessObject { } $this->load(); if ( $this->mId ) { - $this->mTouched = self::newTouchedTimestamp(); + $this->mTouched = $this->newTouchedTimestamp(); $dbw = wfGetDB( DB_MASTER ); $userid = $this->mId; @@ -2307,7 +2313,7 @@ class User implements IDBAccessObject { if ( $this->mId ) { $key = wfMemcKey( 'user-quicktouched', 'id', $this->mId ); - $timestamp = self::newTouchedTimestamp(); + $timestamp = $this->newTouchedTimestamp(); $wgMemc->set( $key, $timestamp ); $this->mQuickTouched = $timestamp; } @@ -3601,7 +3607,7 @@ class User implements IDBAccessObject { wfWarn( "Attempting to save slave-loaded User object data." ); } - $this->mTouched = self::newTouchedTimestamp(); + $this->mTouched = $this->newTouchedTimestamp(); if ( !$wgAuth->allowSetLocalPassword() ) { $this->mPassword = self::getPasswordFactory()->newFromCiphertext( null ); } @@ -3694,7 +3700,7 @@ class User implements IDBAccessObject { 'user_token' => strval( $user->mToken ), 'user_registration' => $dbw->timestamp( $user->mRegistration ), 'user_editcount' => 0, - 'user_touched' => $dbw->timestamp( self::newTouchedTimestamp() ), + 'user_touched' => $dbw->timestamp( $user->newTouchedTimestamp() ), ); foreach ( $params as $name => $value ) { $fields["user_$name"] = $value; @@ -3741,7 +3747,7 @@ class User implements IDBAccessObject { $this->setToken(); // init token } - $this->mTouched = self::newTouchedTimestamp(); + $this->mTouched = $this->newTouchedTimestamp(); $dbw = wfGetDB( DB_MASTER ); $inWrite = $dbw->writesOrCallbacksPending(); -- 2.20.1