[MediaWiki-commits] [Gerrit] Migrate more callers away from $wgMemc - change (mediawiki/core)

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

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

Change subject: Migrate more callers away from $wgMemc
..

Migrate more callers away from $wgMemc

Callers should use more expliciy lazy-loaded
cache factory methods.

Change-Id: Ifa0bf389720a09a931ee6466b993f787d83a09a7
---
M includes/User.php
M includes/api/ApiStashEdit.php
M includes/cache/FileCacheBase.php
M includes/filerepo/ForeignAPIRepo.php
M includes/filerepo/file/File.php
M includes/filerepo/file/ForeignAPIFile.php
M includes/jobqueue/JobQueueDB.php
M includes/jobqueue/JobQueueGroup.php
M includes/specials/SpecialUserlogin.php
9 files changed, 72 insertions(+), 69 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/15/248815/1

diff --git a/includes/User.php b/includes/User.php
index 6e52a1d..3e382d5 100644
--- a/includes/User.php
+++ b/includes/User.php
@@ -1752,8 +1752,6 @@
return false;
}
 
-   global $wgMemc;
-
$limits = $wgRateLimits[$action];
$keys = array();
$id = $this->getId();
@@ -1808,11 +1806,13 @@
$keys[wfMemcKey( 'limiter', $action, 'user', $id )] = 
$userLimit;
}
 
+   $cache = ObjectCache::getLocalClusterInstance();
+
$triggered = false;
foreach ( $keys as $key => $limit ) {
list( $max, $period ) = $limit;
$summary = "(limit $max in {$period}s)";
-   $count = $wgMemc->get( $key );
+   $count = $cache->get( $key );
// Already pinged?
if ( $count ) {
if ( $count >= $max ) {
@@ -1825,11 +1825,11 @@
} else {
wfDebug( __METHOD__ . ": adding record for $key 
$summary\n" );
if ( $incrBy > 0 ) {
-   $wgMemc->add( $key, 0, intval( $period 
) ); // first ping
+   $cache->add( $key, 0, intval( $period ) 
); // first ping
}
}
if ( $incrBy > 0 ) {
-   $wgMemc->incr( $key, $incrBy );
+   $cache->incr( $key, $incrBy );
}
}
 
diff --git a/includes/api/ApiStashEdit.php b/includes/api/ApiStashEdit.php
index e87fc97..ebddd51 100644
--- a/includes/api/ApiStashEdit.php
+++ b/includes/api/ApiStashEdit.php
@@ -39,7 +39,7 @@
const ERROR_UNCACHEABLE = 'uncacheable';
 
public function execute() {
-   global $wgMemc;
+   $cache = ObjectCache::getLocalClusterInstance();
 
$user = $this->getUser();
$params = $this->extractRequestParams();
@@ -111,11 +111,10 @@
// De-duplicate requests on the same key
if ( $user->pingLimiter( 'stashedit' ) ) {
$status = 'ratelimited';
-   } elseif ( $wgMemc->lock( $key, 0, 30 ) ) {
+   } elseif ( $cache->lock( $key, 0, 30 ) ) {
/** @noinspection PhpUnusedLocalVariableInspection */
-   $unlocker = new ScopedCallback( function() use ( $key ) 
{
-   global $wgMemc;
-   $wgMemc->unlock( $key );
+   $unlocker = new ScopedCallback( function() use ( 
$cache, $key ) {
+   $cache->unlock( $key );
} );
$status = self::parseAndStash( $page, $content, $user );
} else {
@@ -133,7 +132,7 @@
 * @since 1.25
 */
public static function parseAndStash( WikiPage $page, Content $content, 
User $user ) {
-   global $wgMemc;
+   $cache = ObjectCache::getLocalClusterInstance();
 
$format = $content->getDefaultFormat();
$editInfo = $page->prepareContentForEdit( $content, null, 
$user, $format, false );
@@ -146,7 +145,7 @@
);
 
if ( $stashInfo ) {
-   $ok = $wgMemc->set( $key, $stashInfo, $ttl );
+   $ok = $cache->set( $key, $stashInfo, $ttl );
if ( $ok ) {
wfDebugLog( 'StashEdit', "Cached parser 
output for key '$key'." );
return self::ERROR_NONE;
@@ -173,7 +172,7 @@
 * will do nothing. Provided the values are cacheable, they will be 
stored
 * in memcached so that final edit submission might make use of them.
 *
-* @param Article|WikiPage $page Page 

[MediaWiki-commits] [Gerrit] Migrate more callers away from $wgMemc - change (mediawiki/core)

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

Change subject: Migrate more callers away from $wgMemc
..


Migrate more callers away from $wgMemc

Callers should use more expliciy lazy-loaded
cache factory methods.

Change-Id: Ifa0bf389720a09a931ee6466b993f787d83a09a7
---
M includes/User.php
M includes/api/ApiStashEdit.php
M includes/cache/FileCacheBase.php
M includes/filerepo/ForeignAPIRepo.php
M includes/filerepo/file/File.php
M includes/filerepo/file/ForeignAPIFile.php
M includes/jobqueue/JobQueueDB.php
M includes/jobqueue/JobQueueGroup.php
M includes/specials/SpecialUserlogin.php
9 files changed, 72 insertions(+), 69 deletions(-)

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



diff --git a/includes/User.php b/includes/User.php
index e1c9e35..1727a4a 100644
--- a/includes/User.php
+++ b/includes/User.php
@@ -1739,8 +1739,6 @@
return false;
}
 
-   global $wgMemc;
-
$limits = $wgRateLimits[$action];
$keys = array();
$id = $this->getId();
@@ -1795,11 +1793,13 @@
$keys[wfMemcKey( 'limiter', $action, 'user', $id )] = 
$userLimit;
}
 
+   $cache = ObjectCache::getLocalClusterInstance();
+
$triggered = false;
foreach ( $keys as $key => $limit ) {
list( $max, $period ) = $limit;
$summary = "(limit $max in {$period}s)";
-   $count = $wgMemc->get( $key );
+   $count = $cache->get( $key );
// Already pinged?
if ( $count ) {
if ( $count >= $max ) {
@@ -1812,11 +1812,11 @@
} else {
wfDebug( __METHOD__ . ": adding record for $key 
$summary\n" );
if ( $incrBy > 0 ) {
-   $wgMemc->add( $key, 0, intval( $period 
) ); // first ping
+   $cache->add( $key, 0, intval( $period ) 
); // first ping
}
}
if ( $incrBy > 0 ) {
-   $wgMemc->incr( $key, $incrBy );
+   $cache->incr( $key, $incrBy );
}
}
 
diff --git a/includes/api/ApiStashEdit.php b/includes/api/ApiStashEdit.php
index e87fc97..ebddd51 100644
--- a/includes/api/ApiStashEdit.php
+++ b/includes/api/ApiStashEdit.php
@@ -39,7 +39,7 @@
const ERROR_UNCACHEABLE = 'uncacheable';
 
public function execute() {
-   global $wgMemc;
+   $cache = ObjectCache::getLocalClusterInstance();
 
$user = $this->getUser();
$params = $this->extractRequestParams();
@@ -111,11 +111,10 @@
// De-duplicate requests on the same key
if ( $user->pingLimiter( 'stashedit' ) ) {
$status = 'ratelimited';
-   } elseif ( $wgMemc->lock( $key, 0, 30 ) ) {
+   } elseif ( $cache->lock( $key, 0, 30 ) ) {
/** @noinspection PhpUnusedLocalVariableInspection */
-   $unlocker = new ScopedCallback( function() use ( $key ) 
{
-   global $wgMemc;
-   $wgMemc->unlock( $key );
+   $unlocker = new ScopedCallback( function() use ( 
$cache, $key ) {
+   $cache->unlock( $key );
} );
$status = self::parseAndStash( $page, $content, $user );
} else {
@@ -133,7 +132,7 @@
 * @since 1.25
 */
public static function parseAndStash( WikiPage $page, Content $content, 
User $user ) {
-   global $wgMemc;
+   $cache = ObjectCache::getLocalClusterInstance();
 
$format = $content->getDefaultFormat();
$editInfo = $page->prepareContentForEdit( $content, null, 
$user, $format, false );
@@ -146,7 +145,7 @@
);
 
if ( $stashInfo ) {
-   $ok = $wgMemc->set( $key, $stashInfo, $ttl );
+   $ok = $cache->set( $key, $stashInfo, $ttl );
if ( $ok ) {
wfDebugLog( 'StashEdit', "Cached parser 
output for key '$key'." );
return self::ERROR_NONE;
@@ -173,7 +172,7 @@
 * will do nothing. Provided the values are cacheable, they will be 
stored
 * in memcached so that final edit submission might make use of them.
 *
-* @param Article|WikiPage $page Page title
+* @param Page|Article|WikiPage