nextcloud/lib/private/Preview/Storage/StorageFactory.php
Carl Schwan b0357663b9 perf(preview): Optimize migration and simplify DB layout
* Simplify migration by not moving the actual files and just updating
  the DB
* Don't store the storageid in the preview table as it is not needed
* Start adding tests

Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
2025-10-06 13:37:15 +02:00

50 lines
1.3 KiB
PHP

<?php
namespace OC\Preview\Storage;
use OC\Files\ObjectStore\PrimaryObjectStoreConfig;
use OC\Files\SimpleFS\SimpleFile;
use OC\Preview\Db\Preview;
use OC\Preview\Db\PreviewMapper;
use OCP\IConfig;
class StorageFactory implements IPreviewStorage {
private ?IPreviewStorage $backend = null;
public function __construct(
private readonly PrimaryObjectStoreConfig $objectStoreConfig,
private readonly IConfig $config,
private readonly PreviewMapper $previewMapper,
) {
}
public function writePreview(Preview $preview, $stream): false|int {
return $this->getBackend()->writePreview($preview, $stream);
}
public function readPreview(Preview $preview) {
return $this->getBackend()->readPreview($preview);
}
public function deletePreview(Preview $preview): void {
$this->getBackend()->deletePreview($preview);
}
private function getBackend(): IPreviewStorage {
if ($this->backend) {
return $this->backend;
}
if ($this->objectStoreConfig->hasObjectStore()) {
$this->backend = new ObjectStorePreviewStorage($this->objectStoreConfig, $this->config, $this->previewMapper);
} else {
$this->backend = new LocalPreviewStorage($this->config);
}
return $this->backend;
}
public function migratePreview(Preview $preview, SimpleFile $file): void {
$this->getBackend()->migratePreview($preview, $file);
}
}