nextcloud/lib/private/Preview/Storage/StorageFactory.php
Carl Schwan 18fbacdd8d perf(preview): Split preview data to new table
The new oc_previews table is optimized for storing previews and should
decrease significantly the space taken by previews in the filecache
table.

This attend to reuse the IObjectStore abstraction over S3/Swift/Azure
but currently only support one single bucket configuration.

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

44 lines
1.3 KiB
PHP

<?php
namespace OC\Preview\Storage;
use OC;
use OC\Files\ObjectStore\PrimaryObjectStoreConfig;
use OC\Preview\Db\Preview;
use OCP\IConfig;
class StorageFactory implements IPreviewStorage {
private ?IPreviewStorage $backend = null;
public function __construct(private PrimaryObjectStoreConfig $objectStoreConfig, private IConfig $config) {}
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) {
$this->getBackend()->deletePreview($preview);
}
private function getBackend(): IPreviewStorage {
if ($this->backend) {
return $this->backend;
}
$objectStoreConfig = $this->objectStoreConfig->getObjectStoreConfigForRoot();
if ($objectStoreConfig) {
$objectStore = $this->objectStoreConfig->buildObjectStore($objectStoreConfig);
$this->backend = new ObjectStorePreviewStorage($objectStore, $objectStoreConfig['arguments']);
} else {
$configDataDirectory = $this->config->getSystemValue('datadirectory', OC::$SERVERROOT . '/data');
$this->backend = new LocalPreviewStorage($configDataDirectory);
}
return $this->backend;
}
}