Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/private/Preview/Storage/ObjectStorePreviewStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ private function getConfigForNewPreview(Preview $preview, bool $migration = fals
if ($config['arguments']['multibucket']) {
if ($this->isMultibucketPreviewDistributionEnabled) {
// Spread the previews on different buckets depending on their corresponding fileId
$oldLocationArray = str_split(substr(md5((string)$preview->getFileId()), 0, 2));
$bucketNumber = hexdec('0x' . $oldLocationArray[0]) * 16 + hexdec('0x' . $oldLocationArray[0]);
$bucketNumber = hexdec(substr(md5((string)$preview->getFileId()), 0, 2));
$bucketName .= '-preview-' . $bucketNumber;
} else {
// Put all previews in the root (0) bucket
Expand Down
22 changes: 13 additions & 9 deletions tests/lib/Preview/Storage/ObjectStorePreviewStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,26 @@ public function testMigratePreviewsLooksUpTheLocationOncePerBucket(): void {

public function testMigratePreviewsWithMultibucketDistribution(): void {
$storage = $this->createStorage(multibucket: true, distribution: true);
// md5('1') and md5('2') start with 'c', md5('3') with 'e'
// The legacy bucket suffix is the first two hex digits of the file ID hash.
$previews = [self::createPreview(1), self::createPreview(2), self::createPreview(3)];

$this->previewMapper->expects($this->exactly(2))
$this->previewMapper->expects($this->exactly(3))
->method('getLocationId')
->willReturnMap([
['nc-preview-204', 'default', '1'],
['nc-preview-238', 'default', '2'],
]);
->willReturnCallback(static fn (string $bucket, string $objectStore): string => match ([$bucket, $objectStore]) {
['nc-preview-196', 'default'] => '1',
['nc-preview-200', 'default'] => '2',
['nc-preview-236', 'default'] => '3',
default => 'unexpected-location',
});

$storage->migratePreviews($previews);

$this->assertSame('nc-preview-196', $previews[0]->getBucketName());
$this->assertSame('nc-preview-200', $previews[1]->getBucketName());
$this->assertSame('nc-preview-236', $previews[2]->getBucketName());
$this->assertSame('1', $previews[0]->getLocationId());
$this->assertSame('1', $previews[1]->getLocationId());
$this->assertSame('2', $previews[2]->getLocationId());
$this->assertSame('nc-preview-238', $previews[2]->getBucketName());
$this->assertSame('2', $previews[1]->getLocationId());
$this->assertSame('3', $previews[2]->getLocationId());
}

/**
Expand Down