X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fpoolcounter%2FPoolCounter.php;h=ba0b4cb318f2d6f389234dc042ab417b84ac850e;hp=acdbd81361b782300dc5d24fef5e199a6b6f92d4;hb=827c6bfa416d9d0de8cc8e22f9f3fa36d8129d44;hpb=a5b975edd132e52ee8ce1c725d8195da941c8b7b diff --git a/includes/poolcounter/PoolCounter.php b/includes/poolcounter/PoolCounter.php index acdbd81361..ba0b4cb318 100644 --- a/includes/poolcounter/PoolCounter.php +++ b/includes/poolcounter/PoolCounter.php @@ -81,7 +81,7 @@ abstract class PoolCounter { /** * @param array $conf - * @param string $type + * @param string $type The class of actions to limit concurrency for (task type) * @param string $key */ protected function __construct( $conf, $type, $key ) { @@ -93,8 +93,9 @@ abstract class PoolCounter { } if ( $this->slots ) { - $key = $this->hashKeyIntoSlots( $key, $this->slots ); + $key = $this->hashKeyIntoSlots( $type, $key, $this->slots ); } + $this->key = $key; $this->isMightWaitKey = !preg_match( '/^nowait:/', $this->key ); } @@ -102,7 +103,7 @@ abstract class PoolCounter { /** * Create a Pool counter. This should only be called from the PoolWorks. * - * @param string $type + * @param string $type The class of actions to limit concurrency for (task type) * @param string $key * * @return PoolCounter @@ -192,24 +193,24 @@ abstract class PoolCounter { } /** - * Given a key (any string) and the number of lots, returns a slot number (an integer from - * the [0..($slots-1)] range). This is used for a global limit on the number of instances of - * a given type that can acquire a lock. The hashing is deterministic so that + * Given a key (any string) and the number of lots, returns a slot key (a prefix with a suffix + * integer from the [0..($slots-1)] range). This is used for a global limit on the number of + * instances of a given type that can acquire a lock. The hashing is deterministic so that * PoolCounter::$workers is always an upper limit of how many instances with the same key * can acquire a lock. * + * @param string $type The class of actions to limit concurrency for (task type) * @param string $key PoolCounter instance key (any string) * @param int $slots The number of slots (max allowed value is 65536) - * @return int + * @return string Slot key with the type and slot number */ - protected function hashKeyIntoSlots( $key, $slots ) { - return hexdec( substr( sha1( $key ), 0, 4 ) ) % $slots; + protected function hashKeyIntoSlots( $type, $key, $slots ) { + return $type . ':' . ( hexdec( substr( sha1( $key ), 0, 4 ) ) % $slots ); } } -// @codingStandardsIgnoreStart Squiz.Classes.ValidClassName.NotCamelCaps +// phpcs:ignore Squiz.Classes.ValidClassName.NotCamelCaps class PoolCounter_Stub extends PoolCounter { - // @codingStandardsIgnoreEnd public function __construct() { /* No parameters needed */