Skip to content

Commit 7848dfb

Browse files
committed
fix: Allow num_buckets to be equal as min_bucket
Signed-off-by: Kostiantyn Miakshyn <[email protected]>
1 parent bbca4fe commit 7848dfb

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/private/Files/ObjectStore/Mapper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public function getBucket(int $numBuckets = 64): string {
3030
? (int)$this->config['arguments']['min_bucket']
3131
: 0;
3232

33+
if ($minBucket === $numBuckets) {
34+
return (string)$minBucket;
35+
}
36+
3337
$hash = md5($this->user->getUID());
3438
$num = hexdec(substr($hash, 0, 4));
3539
return (string)(($num % ($numBuckets - $minBucket)) + $minBucket);

tests/lib/Files/ObjectStore/MapperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ protected function setUp(): void {
2424
public static function dataGetBucket(): array {
2525
return [
2626
['user', 64, 0, '17'],
27+
['user', 64, 64, '64'],
2728
['USER', 64, 0, '0'],
2829
['bc0e8b52-a66c-1035-90c6-d9663bda9e3f', 64, 0, '56'],
2930
['user', 8, 0, '1'],
@@ -41,8 +42,7 @@ public static function dataGetBucket(): array {
4142
#[\PHPUnit\Framework\Attributes\DataProvider('dataGetBucket')]
4243
public function testGetBucket($username, $numBuckets, $bucketShift, $expectedBucket): void {
4344
$mapper = new Mapper($this->user, ['arguments' => ['min_bucket' => $bucketShift]]);
44-
$this->user->expects($this->once())
45-
->method('getUID')
45+
$this->user->method('getUID')
4646
->willReturn($username);
4747

4848
$result = $mapper->getBucket($numBuckets);

0 commit comments

Comments
 (0)