[MediaWiki-commits] [Gerrit] mediawiki/core[master]: objectcache: add WANObjectCache::getMultiCheckKeyTime method

2017-12-01 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/394524 )

Change subject: objectcache: add WANObjectCache::getMultiCheckKeyTime method
..


objectcache: add WANObjectCache::getMultiCheckKeyTime method

Change-Id: I5675fabc5aa70f72659ce02d68caae88be20e06d
---
M includes/libs/objectcache/WANObjectCache.php
M tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
2 files changed, 44 insertions(+), 14 deletions(-)

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



diff --git a/includes/libs/objectcache/WANObjectCache.php 
b/includes/libs/objectcache/WANObjectCache.php
index b337e9e..68da16d 100644
--- a/includes/libs/objectcache/WANObjectCache.php
+++ b/includes/libs/objectcache/WANObjectCache.php
@@ -601,25 +601,54 @@
 * Note that "check" keys won't collide with other regular keys.
 *
 * @param string $key
-* @return float UNIX timestamp of the check key
+* @return float UNIX timestamp
 */
final public function getCheckKeyTime( $key ) {
-   $key = self::TIME_KEY_PREFIX . $key;
+   return $this->getMultiCheckKeyTime( [ $key ] )[$key];
+   }
 
-   $purge = self::parsePurgeValue( $this->cache->get( $key ) );
-   if ( $purge !== false ) {
-   $time = $purge[self::FLD_TIME];
-   } else {
-   // Casting assures identical floats for the next 
getCheckKeyTime() calls
-   $now = (string)$this->getCurrentTime();
-   $this->cache->add( $key,
-   $this->makePurgeValue( $now, self::HOLDOFF_TTL 
),
-   self::CHECK_KEY_TTL
-   );
-   $time = (float)$now;
+   /**
+* Fetch the values of each timestamp "check" key
+*
+* This works like getCheckKeyTime() except it takes a list of keys
+* and returns a list of timestamps instead of just that of one key
+*
+* @see WANObjectCache::getCheckKeyTime()
+*
+* @param array $keys
+* @return float[] Map of (key => UNIX timestamp)
+* @since 1.31
+*/
+   final public function getMultiCheckKeyTime( array $keys ) {
+   $rawKeys = [];
+   foreach ( $keys as $key ) {
+   $rawKeys[$key] = self::TIME_KEY_PREFIX . $key;
}
 
-   return $time;
+   $rawValues = $this->cache->getMulti( $rawKeys );
+   $rawValues += array_fill_keys( $rawKeys, false );
+
+   $index = 0;
+   $times = [];
+   foreach ( $rawKeys as $key => $rawKey ) {
+   $purge = self::parsePurgeValue( $rawValues[$rawKey] );
+   if ( $purge !== false ) {
+   $time = $purge[self::FLD_TIME];
+   } else {
+   // Casting assures identical floats for the 
next getCheckKeyTime() calls
+   $now = (string)$this->getCurrentTime();
+   $this->cache->add(
+   $rawKey,
+   $this->makePurgeValue( $now, 
self::HOLDOFF_TTL ),
+   self::CHECK_KEY_TTL
+   );
+   $time = (float)$now;
+   }
+
+   $times[$key] = $time;
+   }
+
+   return $times;
}
 
/**
diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php 
b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
index f586d03..e534f92 100644
--- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
+++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
@@ -1280,6 +1280,7 @@
 * @covers WANObjectCache::touchCheckKey
 * @covers WANObjectCache::resetCheckKey
 * @covers WANObjectCache::getCheckKeyTime
+* @covers WANObjectCache::getMultiCheckKeyTime
 * @covers WANObjectCache::makePurgeValue
 * @covers WANObjectCache::parsePurgeValue
 */

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5675fabc5aa70f72659ce02d68caae88be20e06d
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz 
Gerrit-Reviewer: Aaron Schulz 
Gerrit-Reviewer: Krinkle 
Gerrit-Reviewer: jenkins-bot <>

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: objectcache: add WANObjectCache::getMultiCheckKeyTime method

2017-11-30 Thread Aaron Schulz (Code Review)
Aaron Schulz has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/394524 )

Change subject: objectcache: add WANObjectCache::getMultiCheckKeyTime method
..

objectcache: add WANObjectCache::getMultiCheckKeyTime method

Change-Id: I5675fabc5aa70f72659ce02d68caae88be20e06d
---
M includes/libs/objectcache/WANObjectCache.php
M tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
2 files changed, 44 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/24/394524/1

diff --git a/includes/libs/objectcache/WANObjectCache.php 
b/includes/libs/objectcache/WANObjectCache.php
index b8d90d9..0bdfed3 100644
--- a/includes/libs/objectcache/WANObjectCache.php
+++ b/includes/libs/objectcache/WANObjectCache.php
@@ -586,25 +586,54 @@
 * Note that "check" keys won't collide with other regular keys.
 *
 * @param string $key
-* @return float UNIX timestamp of the check key
+* @return float UNIX timestamp
 */
final public function getCheckKeyTime( $key ) {
-   $key = self::TIME_KEY_PREFIX . $key;
+   return $this->getMultiCheckKeyTime( [ $key ] )[$key];
+   }
 
-   $purge = self::parsePurgeValue( $this->cache->get( $key ) );
-   if ( $purge !== false ) {
-   $time = $purge[self::FLD_TIME];
-   } else {
-   // Casting assures identical floats for the next 
getCheckKeyTime() calls
-   $now = (string)$this->getCurrentTime();
-   $this->cache->add( $key,
-   $this->makePurgeValue( $now, self::HOLDOFF_TTL 
),
-   self::CHECK_KEY_TTL
-   );
-   $time = (float)$now;
+   /**
+* Fetch the values of each timestamp "check" key
+*
+* This works like getCheckKeyTime() except it takes a list of keys
+* and returns a list of timestamps instead of just that of one key
+*
+* @see WANObjectCache::getCheckKeyTime()
+*
+* @param array $keys
+* @return float[] Map of (key => UNIX timestamps)
+* @since 1.31
+*/
+   final public function getMultiCheckKeyTime( array $keys ) {
+   $rawKeys = [];
+   foreach ( $keys as $key ) {
+   $rawKeys[] = self::TIME_KEY_PREFIX . $key;
}
 
-   return $time;
+   $rawValues = $this->cache->getMulti( $rawKeys );
+   $rawValues += array_fill_keys( $rawKeys, false );
+
+   $index = 0;
+   $times = [];
+   foreach ( $rawKeys as $rawKey ) {
+   $purge = self::parsePurgeValue( $rawValues[$rawKey] );
+   if ( $purge !== false ) {
+   $time = $purge[self::FLD_TIME];
+   } else {
+   // Casting assures identical floats for the 
next getCheckKeyTime() calls
+   $now = (string)$this->getCurrentTime();
+   $this->cache->add(
+   $rawKey,
+   $this->makePurgeValue( $now, 
self::HOLDOFF_TTL ),
+   self::CHECK_KEY_TTL
+   );
+   $time = (float)$now;
+   }
+
+   $times[$keys[$index++]] = $time;
+   }
+
+   return $times;
}
 
/**
diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php 
b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
index d94c546..a0fee8b 100644
--- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
+++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
@@ -1153,6 +1153,7 @@
 * @covers WANObjectCache::touchCheckKey
 * @covers WANObjectCache::resetCheckKey
 * @covers WANObjectCache::getCheckKeyTime
+* @covers WANObjectCache::getCheckKeyTimeMulti
 * @covers WANObjectCache::makePurgeValue
 * @covers WANObjectCache::parsePurgeValue
 */

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5675fabc5aa70f72659ce02d68caae88be20e06d
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