Skip to content

Commit 4e3986f

Browse files
committed
fix: make bucket mapper work with new multi-object-store config
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent a7338b0 commit 4e3986f

File tree

3 files changed

+10
-38
lines changed

3 files changed

+10
-38
lines changed

lib/private/Files/ObjectStore/Mapper.php

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,17 @@
1818
* Map a user to a bucket.
1919
*/
2020
class Mapper {
21-
/** @var IUser */
22-
private $user;
23-
24-
/** @var IConfig */
25-
private $config;
26-
27-
/**
28-
* Mapper constructor.
29-
*
30-
* @param IUser $user
31-
* @param IConfig $config
32-
*/
33-
public function __construct(IUser $user, IConfig $config) {
34-
$this->user = $user;
35-
$this->config = $config;
21+
public function __construct(
22+
private readonly IUser $user,
23+
private readonly array $config
24+
) {
3625
}
3726

38-
/**
39-
* @param int $numBuckets
40-
* @return string
41-
*/
42-
public function getBucket($numBuckets = 64) {
27+
public function getBucket(int $numBuckets = 64): string {
4328
// Get the bucket config and shift if provided.
4429
// Allow us to prevent writing in old filled buckets
45-
$config = $this->config->getSystemValue('objectstore_multibucket');
46-
$minBucket = is_array($config) && isset($config['arguments']['min_bucket'])
47-
? (int)$config['arguments']['min_bucket']
30+
$minBucket = isset($this->config['arguments']['min_bucket'])
31+
? (int)$this->config['arguments']['min_bucket']
4832
: 0;
4933

5034
$hash = md5($this->user->getUID());

lib/private/Files/ObjectStore/PrimaryObjectStoreConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public function getBucketForUser(IUser $user, array $config): string {
196196
if (!isset($config['arguments']['bucket'])) {
197197
$config['arguments']['bucket'] = '';
198198
}
199-
$mapper = new Mapper($user, $this->config);
199+
$mapper = new Mapper($user, $config);
200200
$numBuckets = $config['arguments']['num_buckets'] ?? 64;
201201
$bucket = $config['arguments']['bucket'] . $mapper->getBucket($numBuckets);
202202

tests/lib/Files/ObjectStore/MapperTest.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,10 @@ class MapperTest extends \Test\TestCase {
1616
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
1717
private $user;
1818

19-
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
20-
private $config;
21-
22-
/** @var Mapper */
23-
private $mapper;
24-
2519
protected function setUp(): void {
2620
parent::setUp();
2721

2822
$this->user = $this->createMock(IUser::class);
29-
$this->config = $this->createMock(IConfig::class);
30-
$this->mapper = new Mapper($this->user, $this->config);
3123
}
3224

3325
public static function dataGetBucket(): array {
@@ -49,16 +41,12 @@ public static function dataGetBucket(): array {
4941
*/
5042
#[\PHPUnit\Framework\Attributes\DataProvider('dataGetBucket')]
5143
public function testGetBucket($username, $numBuckets, $bucketShift, $expectedBucket): void {
44+
$mapper = new Mapper($this->user, ['min_bucket' => $bucketShift]);
5245
$this->user->expects($this->once())
5346
->method('getUID')
5447
->willReturn($username);
5548

56-
$this->config->expects($this->once())
57-
->method('getSystemValue')
58-
->with('objectstore_multibucket')
59-
->willReturn(['arguments' => ['min_bucket' => $bucketShift]]);
60-
61-
$result = $this->mapper->getBucket($numBuckets);
49+
$result = $mapper->getBucket($numBuckets);
6250
$this->assertEquals($expectedBucket, $result);
6351
}
6452
}

0 commit comments

Comments
 (0)