]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add config option to enable multibucket preview distribution 22063/head
authorMorris Jobke <hey@morrisjobke.de>
Thu, 6 Aug 2020 18:10:25 +0000 (20:10 +0200)
committerMorris Jobke <hey@morrisjobke.de>
Thu, 6 Aug 2020 20:31:39 +0000 (22:31 +0200)
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
config/config.sample.php
lib/private/Files/Mount/ObjectStorePreviewCacheMountProvider.php
lib/private/Preview/Storage/Root.php
tests/lib/Files/Mount/ObjectStorePreviewCacheMountProviderTest.php

index e95f2535af81d1f62a2456487d23b2e494e6b46e..862c5ec1a1d6b195932eeb2ad715b0fa91f8ee56 100644 (file)
@@ -1354,6 +1354,23 @@ $CONFIG = [
        ],
 ],
 
+/**
+ * If this is set to true and a multibucket object store is configured then
+ * newly created previews are put into 256 dedicated buckets.
+ *
+ * Those buckets are named like the mulibucket version but with the postfix
+ * ``-preview-NUMBER`` where NUMBER is between 0 and 255.
+ *
+ * Keep in mind that only previews of files are put in there that don't have
+ * some already. Otherwise the old bucket will be used.
+ *
+ * To migrate existing previews to this new multibucket distribution of previews
+ * use the occ command ``preview:repair``. For now this will only migrate
+ * previews that were generated before Nextcloud 19 in the flat
+ * ``appdata_INSTANCEID/previews/FILEID`` folder structure.
+ */
+'objectstore.multibucket.preview-distribution' => false,
+
 
 /**
  * Sharing
index dba1dfc28e536204061539ae9cc3bf299e3c6be3..9bbb744bbcc23a4dce150dba003672d860237e23 100644 (file)
@@ -55,6 +55,9 @@ class ObjectStorePreviewCacheMountProvider implements IRootMountProvider {
                if (!is_array($this->config->getSystemValue('objectstore_multibucket'))) {
                        return [];
                }
+               if ($this->config->getSystemValue('objectstore.multibucket.preview-distribution', false) !== true) {
+                       return [];
+               }
 
                $instanceId = $this->config->getSystemValueString('instanceid', '');
                $mountPoints = [];
index 37ae1758121cc04b3fd4188ed6b3f1904b8498b2..a284b037b3558ff1d228c3822d3c3a39ee719597 100644 (file)
@@ -32,23 +32,23 @@ use OCP\Files\NotFoundException;
 use OCP\Files\SimpleFS\ISimpleFolder;
 
 class Root extends AppData {
+       private $isMultibucketPreviewDistributionEnabled = false;
        public function __construct(IRootFolder $rootFolder, SystemConfig $systemConfig) {
                parent::__construct($rootFolder, $systemConfig, 'preview');
+
+               $this->isMultibucketPreviewDistributionEnabled = $systemConfig->getValue('objectstore.multibucket.preview-distribution', false) === true;
        }
 
 
        public function getFolder(string $name): ISimpleFolder {
                $internalFolder = $this->getInternalFolder($name);
 
-               try {
-                       return parent::getFolder('old-multibucket/' . $internalFolder);
-               } catch (NotFoundException $e) {
-                       // not in multibucket fallback #1
-               }
-               try {
-                       return parent::getFolder('old-multibucket/' . $name);
-               } catch (NotFoundException $e) {
-                       // not in multibucket fallback #2
+               if ($this->isMultibucketPreviewDistributionEnabled) {
+                       try {
+                               return parent::getFolder('old-multibucket/' . $internalFolder);
+                       } catch (NotFoundException $e) {
+                               // not in multibucket fallback
+                       }
                }
 
                try {
index 2da07393f40ab558a8372bb4f4a58cad533d83f4..400808d7cd5ea761e7af9e7ca14b371c2106c422 100644 (file)
@@ -71,22 +71,29 @@ class ObjectStorePreviewCacheMountProviderTest extends \Test\TestCase {
        }
 
        public function testMultibucketObjectStorage() {
+               $objectstoreConfig = [
+                       'class' => S3::class,
+                       'arguments' => [
+                               'bucket' => 'abc',
+                               'num_buckets' => 64,
+                               'key' => 'KEY',
+                               'secret' => 'SECRET',
+                               'hostname' => 'IP',
+                               'port' => 'PORT',
+                               'use_ssl' => false,
+                               'use_path_style' => true,
+                       ],
+               ];
                $this->config->expects($this->any())
                        ->method('getSystemValue')
-                       ->with('objectstore_multibucket')
-                       ->willReturn([
-                               'class' => S3::class,
-                               'arguments' => [
-                                       'bucket' => 'abc',
-                                       'num_buckets' => 64,
-                                       'key' => 'KEY',
-                                       'secret' => 'SECRET',
-                                       'hostname' => 'IP',
-                                       'port' => 'PORT',
-                                       'use_ssl' => false,
-                                       'use_path_style' => true,
-                               ],
-                       ]);
+                       ->willReturnCallback(function ($config) use ($objectstoreConfig) {
+                               if ($config === 'objectstore_multibucket') {
+                                       return $objectstoreConfig;
+                               } elseif ($config === 'objectstore.multibucket.preview-distribution') {
+                                       return true;
+                               }
+                               return null;
+                       });
                $this->config->expects($this->once())
                        ->method('getSystemValueString')
                        ->with('instanceid')