Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2020-01-30 13:37:01 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2020-04-19 11:30:56 +0300
commit6c603e8e7d1ac52eeefdda939fa96a0c27b7c3da (patch)
tree82c496f7f12dcc4a482ff3f201d8e16f98022ae9 /tests/lib/Preview
parent64196ddd19684b6a218428eeb6ee370d0514b68c (diff)
Move to subfolders for preview files
Else the number of files can grow very large very quickly in the preview folder. Esp on large systems. This generates the md5 of the fileid. And then creates folders of the first 7 charts. In that folder is then a folder with the fileid. And inside there are the previews. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'tests/lib/Preview')
-rw-r--r--tests/lib/Preview/BackgroundCleanupJobTest.php96
1 files changed, 70 insertions, 26 deletions
diff --git a/tests/lib/Preview/BackgroundCleanupJobTest.php b/tests/lib/Preview/BackgroundCleanupJobTest.php
index db2bf09b6e5..cd9f6ef0399 100644
--- a/tests/lib/Preview/BackgroundCleanupJobTest.php
+++ b/tests/lib/Preview/BackgroundCleanupJobTest.php
@@ -22,10 +22,13 @@
namespace Test\Preview;
-use OC\Files\AppData\Factory;
use OC\Preview\BackgroundCleanupJob;
+use OC\Preview\Storage\Root;
use OC\PreviewManager;
+use OCP\Files\File;
+use OCP\Files\IMimeTypeLoader;
use OCP\Files\IRootFolder;
+use OCP\Files\NotFoundException;
use OCP\IDBConnection;
use Test\Traits\MountProviderTrait;
use Test\Traits\UserTrait;
@@ -47,9 +50,6 @@ class BackgroundCleanupJobTest extends \Test\TestCase {
/** @var bool */
private $trashEnabled;
- /** @var Factory */
- private $appDataFactory;
-
/** @var IDBConnection */
private $connection;
@@ -59,6 +59,9 @@ class BackgroundCleanupJobTest extends \Test\TestCase {
/** @var IRootFolder */
private $rootFolder;
+ /** @var IMimeTypeLoader */
+ private $mimeTypeLoader;
+
protected function setUp(): void {
parent::setUp();
@@ -76,13 +79,10 @@ class BackgroundCleanupJobTest extends \Test\TestCase {
$this->trashEnabled = $appManager->isEnabledForUser('files_trashbin', $this->userId);
$appManager->disableApp('files_trashbin');
- $this->appDataFactory = new Factory(
- \OC::$server->getRootFolder(),
- \OC::$server->getSystemConfig()
- );
$this->connection = \OC::$server->getDatabaseConnection();
$this->previewManager = \OC::$server->getPreviewManager();
$this->rootFolder = \OC::$server->getRootFolder();
+ $this->mimeTypeLoader = \OC::$server->getMimeTypeLoader();
}
protected function tearDown(): void {
@@ -96,6 +96,13 @@ class BackgroundCleanupJobTest extends \Test\TestCase {
parent::tearDown();
}
+ private function getRoot(): Root {
+ return new Root(
+ \OC::$server->getRootFolder(),
+ \OC::$server->getSystemConfig()
+ );
+ }
+
private function setup11Previews(): array {
$userFolder = $this->rootFolder->getUserFolder($this->userId);
@@ -110,52 +117,89 @@ class BackgroundCleanupJobTest extends \Test\TestCase {
return $files;
}
+ private function countPreviews(Root $previewRoot, array $fileIds): int {
+ $i = 0;
+
+ foreach ($fileIds as $fileId) {
+ try {
+ $previewRoot->getFolder((string)$fileId);
+ } catch (NotFoundException $e) {
+ continue;
+ }
+
+ $i++;
+ }
+
+ return $i;
+ }
+
public function testCleanupSystemCron() {
$files = $this->setup11Previews();
+ $fileIds = array_map(function (File $f) {
+ return $f->getId();
+ }, $files);
- $preview = $this->appDataFactory->get('preview');
-
- $previews = $preview->getDirectoryListing();
- $this->assertCount(11, $previews);
+ $root = $this->getRoot();
- $job = new BackgroundCleanupJob($this->connection, $this->appDataFactory, true);
+ $this->assertSame(11, $this->countPreviews($root, $fileIds));
+ $job = new BackgroundCleanupJob($this->connection, $root, $this->mimeTypeLoader, true);
$job->run([]);
foreach ($files as $file) {
$file->delete();
}
- $this->assertCount(11, $previews);
+ $root = $this->getRoot();
+ $this->assertSame(11, $this->countPreviews($root, $fileIds));
$job->run([]);
- $previews = $preview->getDirectoryListing();
- $this->assertCount(0, $previews);
+ $root = $this->getRoot();
+ $this->assertSame(0, $this->countPreviews($root, $fileIds));
}
public function testCleanupAjax() {
$files = $this->setup11Previews();
+ $fileIds = array_map(function (File $f) {
+ return $f->getId();
+ }, $files);
- $preview = $this->appDataFactory->get('preview');
-
- $previews = $preview->getDirectoryListing();
- $this->assertCount(11, $previews);
+ $root = $this->getRoot();
- $job = new BackgroundCleanupJob($this->connection, $this->appDataFactory, false);
+ $this->assertSame(11, $this->countPreviews($root, $fileIds));
+ $job = new BackgroundCleanupJob($this->connection, $root, $this->mimeTypeLoader, false);
$job->run([]);
foreach ($files as $file) {
$file->delete();
}
- $this->assertCount(11, $previews);
+ $root = $this->getRoot();
+ $this->assertSame(11, $this->countPreviews($root, $fileIds));
$job->run([]);
- $previews = $preview->getDirectoryListing();
- $this->assertCount(1, $previews);
+ $root = $this->getRoot();
+ $this->assertSame(1, $this->countPreviews($root, $fileIds));
+ $job->run([]);
+
+ $root = $this->getRoot();
+ $this->assertSame(0, $this->countPreviews($root, $fileIds));
+ }
+
+ public function testOldPreviews() {
+ $appdata = \OC::$server->getAppDataDir('preview');
+
+ $f1 = $appdata->newFolder('123456781');
+ $f1->newFile('foo.jpg', 'foo');
+ $f2 = $appdata->newFolder('123456782');
+ $f2->newFile('foo.jpg', 'foo');
+
+ $appdata = \OC::$server->getAppDataDir('preview');
+ $this->assertSame(2, count($appdata->getDirectoryListing()));
+ $job = new BackgroundCleanupJob($this->connection, $this->getRoot(), $this->mimeTypeLoader, true);
$job->run([]);
- $previews = $preview->getDirectoryListing();
- $this->assertCount(0, $previews);
+ $appdata = \OC::$server->getAppDataDir('preview');
+ $this->assertSame(0, count($appdata->getDirectoryListing()));
}
}