From b72a00383a5e351b0719c2b178043ddea46d2f44 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 13 Jul 2019 13:16:44 -0700 Subject: [PATCH] objectcache: make BagOStuff::getMulti() preserve order and omit keys with missing segments A key missing segments should count as non-existing, meaning that it should not appear in the return value at all Change-Id: I0f08b3dba77e0d335ebb2d75061927ebd36570d2 --- includes/libs/objectcache/BagOStuff.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/includes/libs/objectcache/BagOStuff.php b/includes/libs/objectcache/BagOStuff.php index c47f6eeabc..dce49c4a46 100644 --- a/includes/libs/objectcache/BagOStuff.php +++ b/includes/libs/objectcache/BagOStuff.php @@ -682,25 +682,33 @@ abstract class BagOStuff implements IExpiringStore, IStoreKeyEncoder, LoggerAwar /** * Get an associative array containing the item for each of the keys that have items. - * @param string[] $keys List of keys + * @param string[] $keys List of keys; can be a map of (unused => key) for convenience * @param int $flags Bitfield; supports READ_LATEST [optional] - * @return array Map of (key => value) for existing keys + * @return mixed[] Map of (key => value) for existing keys; preserves the order of $keys */ public function getMulti( array $keys, $flags = 0 ) { - $valuesBykey = $this->doGetMulti( $keys, $flags ); - foreach ( $valuesBykey as $key => $value ) { + $foundByKey = $this->doGetMulti( $keys, $flags ); + + $res = []; + foreach ( $keys as $key ) { // Resolve one blob at a time (avoids too much I/O at once) - $valuesBykey[$key] = $this->resolveSegments( $key, $value ); + if ( array_key_exists( $key, $foundByKey ) ) { + // A value should not appear in the key if a segment is missing + $value = $this->resolveSegments( $key, $foundByKey[$key] ); + if ( $value !== false ) { + $res[$key] = $value; + } + } } - return $valuesBykey; + return $res; } /** * Get an associative array containing the item for each of the keys that have items. * @param string[] $keys List of keys * @param int $flags Bitfield; supports READ_LATEST [optional] - * @return array Map of (key => value) for existing keys + * @return mixed[] Map of (key => value) for existing keys */ protected function doGetMulti( array $keys, $flags = 0 ) { $res = []; -- 2.20.1