This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 151
SUS-1620 | Introduced User::touch() method to bump the getTouched() value using memcached #12923
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,12 +130,18 @@ class User implements JsonSerializable { | |
/** @name Cache variables */ | ||
//@{ | ||
var $mId, $mName, $mRealName, | ||
$mEmail, $mTouched, $mToken, $mEmailAuthenticated, | ||
$mEmail, $mToken, $mEmailAuthenticated, | ||
$mEmailToken, $mEmailTokenExpires, $mRegistration, $mGroups, $mOptionOverrides, | ||
$mCookiePassword, $mEditCount, $mAllowUsertalk; | ||
var $mBirthDate; // Wikia. Added to reflect our user table layout. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
//@} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
/** @var string TS_MW timestamp from the DB */ | ||
public $mTouched; | ||
|
||
/** @var string TS_MW timestamp from cache */ | ||
protected $mQuickTouched; | ||
|
||
/** | ||
* Bool Whether the cache variables have been loaded. | ||
*/ | ||
|
@@ -2001,51 +2007,42 @@ private function clearSharedCache() { | |
|
||
/** | ||
* Immediately touch the user data cache for this account. | ||
* Updates user_touched field, and removes account data from memcached | ||
* for reload on the next hit. | ||
* | ||
* Calls touch() and removes account data from memcached | ||
* | ||
* @see SUS-1620 | ||
*/ | ||
public function invalidateCache() { | ||
#<Wikia> | ||
global $wgLogUserInvalidateCache; | ||
if ( !empty( $wgLogUserInvalidateCache ) ) { | ||
$e = new Exception; | ||
$this->error( 'SUS-546', [ 'traceBack' => $e->getTraceAsString() ] ); | ||
} | ||
#</Wikia> | ||
if( wfReadOnly() ) { | ||
return; | ||
} | ||
$this->load(); | ||
if ( wfReadOnly() ) { | ||
return; | ||
} | ||
if( $this->mId ) { | ||
$this->mTouched = self::newTouchedTimestamp(); | ||
$this->touch(); | ||
$this->clearSharedCache(); | ||
|
||
#<Wikia> | ||
global $wgExternalSharedDB, $wgSharedDB; | ||
if( isset( $wgSharedDB ) ) { | ||
$dbw = wfGetDB( DB_MASTER, array(), $wgExternalSharedDB ); | ||
} | ||
else { | ||
$dbw = wfGetDB( DB_MASTER ); | ||
} | ||
#</Wikia> | ||
// Wikia change | ||
self::permissionsService()->invalidateCache( $this ); | ||
} | ||
|
||
$touched = $dbw->timestamp( $this->mTouched ); | ||
$needsPurge = $dbw->selectField( | ||
'`user`', '1', | ||
array( 'user_id' => $this->mId, 'user_touched < ' . $dbw->addQuotes( $touched ) ), | ||
__METHOD__ ); | ||
/** | ||
* Update the "touched" timestamp for the user | ||
* | ||
* This is useful on various login/logout events when making sure that | ||
* a browser or proxy that has multiple tenants does not suffer cache | ||
* pollution where the new user sees the old users content. The value | ||
* of getTouched() is checked when determining 304 vs 200 responses. | ||
* Unlike invalidateCache(), this preserves the User object cache and | ||
* avoids database writes. | ||
* | ||
* @@see SUS-1620 | ||
* @since 1.25 | ||
*/ | ||
public function touch() { | ||
global $wgMemc; | ||
|
||
if ( $needsPurge ) { | ||
$dbw->update( '`user`', | ||
array( 'user_touched' => $touched ), array( 'user_id' => $this->mId ), | ||
__METHOD__ ); | ||
} | ||
self::permissionsService()->invalidateCache( $this ); | ||
$this->load(); | ||
|
||
$this->clearSharedCache(); | ||
if ( $this->mId ) { | ||
$key = wfSharedMemcKey( 'user-quicktouched', 'id', $this->mId ); | ||
$timestamp = self::newTouchedTimestamp(); | ||
$wgMemc->set( $key, $timestamp ); | ||
$this->mQuickTouched = $timestamp; | ||
} | ||
} | ||
|
||
|
@@ -2062,10 +2059,26 @@ public function validateCache( $timestamp ) { | |
|
||
/** | ||
* Get the user touched timestamp | ||
* @return String timestamp | ||
* @return string TS_MW Timestamp | ||
*/ | ||
public function getTouched() { | ||
global $wgMemc; | ||
|
||
$this->load(); | ||
|
||
if ( $this->mId ) { | ||
if ( $this->mQuickTouched === null ) { | ||
$key = wfSharedMemcKey( 'user-quicktouched', 'id', $this->mId ); | ||
$timestamp = $wgMemc->get( $key ); | ||
if ( !$timestamp ) { | ||
# Set the timestamp to get HTTP 304 cache hits | ||
$this->touch(); | ||
} | ||
} | ||
|
||
return max( $this->mTouched, $this->mQuickTouched ); | ||
} | ||
|
||
return $this->mTouched; | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this commented out code.