mirror of
https://github.com/nextcloud/server.git
synced 2026-06-22 07:00:02 -04:00
fix: make bucket mapper work with new multi-object-store config
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
b79f93be65
commit
968d3d9ca4
3 changed files with 10 additions and 40 deletions
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
namespace OC\Files\ObjectStore;
|
||||
|
||||
use OCP\IConfig;
|
||||
use OCP\IUser;
|
||||
|
||||
/**
|
||||
|
|
@ -18,33 +17,17 @@ use OCP\IUser;
|
|||
* Map a user to a bucket.
|
||||
*/
|
||||
class Mapper {
|
||||
/** @var IUser */
|
||||
private $user;
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* Mapper constructor.
|
||||
*
|
||||
* @param IUser $user
|
||||
* @param IConfig $config
|
||||
*/
|
||||
public function __construct(IUser $user, IConfig $config) {
|
||||
$this->user = $user;
|
||||
$this->config = $config;
|
||||
public function __construct(
|
||||
private readonly IUser $user,
|
||||
private readonly array $config,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $numBuckets
|
||||
* @return string
|
||||
*/
|
||||
public function getBucket($numBuckets = 64) {
|
||||
public function getBucket(int $numBuckets = 64): string {
|
||||
// Get the bucket config and shift if provided.
|
||||
// Allow us to prevent writing in old filled buckets
|
||||
$config = $this->config->getSystemValue('objectstore_multibucket');
|
||||
$minBucket = is_array($config) && isset($config['arguments']['min_bucket'])
|
||||
? (int)$config['arguments']['min_bucket']
|
||||
$minBucket = isset($this->config['arguments']['min_bucket'])
|
||||
? (int)$this->config['arguments']['min_bucket']
|
||||
: 0;
|
||||
|
||||
$hash = md5($this->user->getUID());
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ class PrimaryObjectStoreConfig {
|
|||
if (!isset($config['arguments']['bucket'])) {
|
||||
$config['arguments']['bucket'] = '';
|
||||
}
|
||||
$mapper = new Mapper($user, $this->config);
|
||||
$mapper = new Mapper($user, $config);
|
||||
$numBuckets = $config['arguments']['num_buckets'] ?? 64;
|
||||
$bucket = $config['arguments']['bucket'] . $mapper->getBucket($numBuckets);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,25 +8,16 @@
|
|||
namespace Test\Files\ObjectStore;
|
||||
|
||||
use OC\Files\ObjectStore\Mapper;
|
||||
use OCP\IConfig;
|
||||
use OCP\IUser;
|
||||
|
||||
class MapperTest extends \Test\TestCase {
|
||||
/** @var IUser|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $user;
|
||||
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $config;
|
||||
|
||||
/** @var Mapper */
|
||||
private $mapper;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->user = $this->createMock(IUser::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->mapper = new Mapper($this->user, $this->config);
|
||||
}
|
||||
|
||||
public function dataGetBucket() {
|
||||
|
|
@ -48,16 +39,12 @@ class MapperTest extends \Test\TestCase {
|
|||
* @param string $expectedBucket
|
||||
*/
|
||||
public function testGetBucket($username, $numBuckets, $bucketShift, $expectedBucket): void {
|
||||
$mapper = new Mapper($this->user, ['arguments' => ['min_bucket' => $bucketShift]]);
|
||||
$this->user->expects($this->once())
|
||||
->method('getUID')
|
||||
->willReturn($username);
|
||||
|
||||
$this->config->expects($this->once())
|
||||
->method('getSystemValue')
|
||||
->with('objectstore_multibucket')
|
||||
->willReturn(['arguments' => ['min_bucket' => $bucketShift]]);
|
||||
|
||||
$result = $this->mapper->getBucket($numBuckets);
|
||||
$result = $mapper->getBucket($numBuckets);
|
||||
$this->assertEquals($expectedBucket, $result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue