Skip to content

Commit f2de5c7

Browse files
Merge pull request #54721 from nextcloud/bucket-mapper-fixes
fix: make bucket mapper work with new multi-object-store config
2 parents 809bbe3 + 02f4a82 commit f2de5c7

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
@@ -7,7 +7,6 @@
77
*/
88
namespace OC\Files\ObjectStore;
99

10-
use OCP\IConfig;
1110
use OCP\IUser;
1211

1312
/**
@@ -18,33 +17,17 @@
1817
* Map a user to a bucket.
1918
*/
2019
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;
20+
public function __construct(
21+
private readonly IUser $user,
22+
private readonly array $config,
23+
) {
3624
}
3725

38-
/**
39-
* @param int $numBuckets
40-
* @return string
41-
*/
42-
public function getBucket($numBuckets = 64) {
26+
public function getBucket(int $numBuckets = 64): string {
4327
// Get the bucket config and shift if provided.
4428
// 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']
29+
$minBucket = isset($this->config['arguments']['min_bucket'])
30+
? (int)$this->config['arguments']['min_bucket']
4831
: 0;
4932

5033
$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
@@ -9,25 +9,16 @@
99
namespace Test\Files\ObjectStore;
1010

1111
use OC\Files\ObjectStore\Mapper;
12-
use OCP\IConfig;
1312
use OCP\IUser;
1413

1514
class MapperTest extends \Test\TestCase {
1615
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
1716
private $user;
1817

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

2821
$this->user = $this->createMock(IUser::class);
29-
$this->config = $this->createMock(IConfig::class);
30-
$this->mapper = new Mapper($this->user, $this->config);
3122
}
3223

3324
public static function dataGetBucket(): array {
@@ -49,16 +40,12 @@ public static function dataGetBucket(): array {
4940
*/
5041
#[\PHPUnit\Framework\Attributes\DataProvider('dataGetBucket')]
5142
public function testGetBucket($username, $numBuckets, $bucketShift, $expectedBucket): void {
43+
$mapper = new Mapper($this->user, ['arguments' => ['min_bucket' => $bucketShift]]);
5244
$this->user->expects($this->once())
5345
->method('getUID')
5446
->willReturn($username);
5547

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);
48+
$result = $mapper->getBucket($numBuckets);
6249
$this->assertEquals($expectedBucket, $result);
6350
}
6451
}

0 commit comments

Comments
 (0)