[MediaWiki-commits] [Gerrit] Made User::newTouchedTimestamp handle clock skew a bit better - change (mediawiki/core)

2015-04-06 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Made User::newTouchedTimestamp handle clock skew a bit better
..


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
---
M includes/User.php
1 file changed, 13 insertions(+), 7 deletions(-)

Approvals:
  Anomie: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/User.php b/includes/User.php
index 322f8af..6ac320e 100644
--- a/includes/User.php
+++ b/includes/User.php
@@ -2233,9 +2233,15 @@
 * 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 @@
}
$this->load();
if ( $this->mId ) {
-   $this->mTouched = self::newTouchedTimestamp();
+   $this->mTouched = $this->newTouchedTimestamp();
 
$dbw = wfGetDB( DB_MASTER );
$userid = $this->mId;
@@ -2307,7 +2313,7 @@
 
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 @@
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 @@
'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 @@
$this->setToken(); // init token
}
 
-   $this->mTouched = self::newTouchedTimestamp();
+   $this->mTouched = $this->newTouchedTimestamp();
 
$dbw = wfGetDB( DB_MASTER );
$inWrite = $dbw->writesOrCallbacksPending();

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I9c31c272fcf77b686764b7c3a6a32ac29576347c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz 
Gerrit-Reviewer: Anomie 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] Made User::newTouchedTimestamp handle clock skew a bit better - change (mediawiki/core)

2015-04-06 Thread Aaron Schulz (Code Review)
Aaron Schulz has uploaded a new change for review.

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

Change subject: Made User::newTouchedTimestamp handle clock skew a bit better
..

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
---
M includes/User.php
1 file changed, 13 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/79/202079/1

diff --git a/includes/User.php b/includes/User.php
index 322f8af..6ac320e 100644
--- a/includes/User.php
+++ b/includes/User.php
@@ -2233,9 +2233,15 @@
 * 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 @@
}
$this->load();
if ( $this->mId ) {
-   $this->mTouched = self::newTouchedTimestamp();
+   $this->mTouched = $this->newTouchedTimestamp();
 
$dbw = wfGetDB( DB_MASTER );
$userid = $this->mId;
@@ -2307,7 +2313,7 @@
 
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 @@
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 @@
'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 @@
$this->setToken(); // init token
}
 
-   $this->mTouched = self::newTouchedTimestamp();
+   $this->mTouched = $this->newTouchedTimestamp();
 
$dbw = wfGetDB( DB_MASTER );
$inWrite = $dbw->writesOrCallbacksPending();

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9c31c272fcf77b686764b7c3a6a32ac29576347c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz 

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