Skip to content

Commit 37fc6cd

Browse files
committed
fix: make bucket mapper work with new multi-object-store config
Signed-off-by: Robin Appelman <[email protected]>
1 parent 7b47728 commit 37fc6cd

File tree

3 files changed

+10
-40
lines changed

3 files changed

+10
-40
lines changed

lib/private/Files/ObjectStore/Mapper.php

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323
namespace OC\Files\ObjectStore;
2424

25-
use OCP\IConfig;
2625
use OCP\IUser;
2726

2827
/**
@@ -33,33 +32,17 @@
3332
* Map a user to a bucket.
3433
*/
3534
class Mapper {
36-
/** @var IUser */
37-
private $user;
38-
39-
/** @var IConfig */
40-
private $config;
41-
42-
/**
43-
* Mapper constructor.
44-
*
45-
* @param IUser $user
46-
* @param IConfig $config
47-
*/
48-
public function __construct(IUser $user, IConfig $config) {
49-
$this->user = $user;
50-
$this->config = $config;
35+
public function __construct(
36+
private IUser $user,
37+
private array $config,
38+
) {
5139
}
5240

53-
/**
54-
* @param int $numBuckets
55-
* @return string
56-
*/
57-
public function getBucket($numBuckets = 64) {
41+
public function getBucket(int $numBuckets = 64): string {
5842
// Get the bucket config and shift if provided.
5943
// Allow us to prevent writing in old filled buckets
60-
$config = $this->config->getSystemValue('objectstore_multibucket');
61-
$minBucket = is_array($config) && isset($config['arguments']['min_bucket'])
62-
? (int)$config['arguments']['min_bucket']
44+
$minBucket = isset($this->config['arguments']['min_bucket'])
45+
? (int) $this->config['arguments']['min_bucket']
6346
: 0;
6447

6548
$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 & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,16 @@
2222
namespace Test\Files\ObjectStore;
2323

2424
use OC\Files\ObjectStore\Mapper;
25-
use OCP\IConfig;
2625
use OCP\IUser;
2726

2827
class MapperTest extends \Test\TestCase {
2928
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
3029
private $user;
3130

32-
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
33-
private $config;
34-
35-
/** @var Mapper */
36-
private $mapper;
37-
3831
protected function setUp(): void {
3932
parent::setUp();
4033

4134
$this->user = $this->createMock(IUser::class);
42-
$this->config = $this->createMock(IConfig::class);
43-
$this->mapper = new Mapper($this->user, $this->config);
4435
}
4536

4637
public function dataGetBucket() {
@@ -62,16 +53,12 @@ public function dataGetBucket() {
6253
* @param string $expectedBucket
6354
*/
6455
public function testGetBucket($username, $numBuckets, $bucketShift, $expectedBucket) {
56+
$mapper = new Mapper($this->user, ['arguments' => ['min_bucket' => $bucketShift]]);
6557
$this->user->expects($this->once())
6658
->method('getUID')
6759
->willReturn($username);
6860

69-
$this->config->expects($this->once())
70-
->method('getSystemValue')
71-
->with('objectstore_multibucket')
72-
->willReturn(['arguments' => ['min_bucket' => $bucketShift]]);
73-
74-
$result = $this->mapper->getBucket($numBuckets);
61+
$result = $mapper->getBucket($numBuckets);
7562
$this->assertEquals($expectedBucket, $result);
7663
}
7764
}

0 commit comments

Comments
 (0)