Kill the dete preview watcher

This code had the potential to time out. If a huge folder with pictures
for example was deleted then this could easily grow the number of files
to clean with a factor 5 (or more).

Now the previews just get cleaned up in the background. Which is good
enough for the 99% case

As a bonus this now also keeps the previews when in the trashbin so you
don't have a spiking server load when a user opens the trashbin view.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-05-08 14:52:36 +02:00
parent 253f962241
commit 3e07c4f73a
No known key found for this signature in database
GPG Key ID: F941078878347C0C
2 changed files with 4 additions and 51 deletions

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl> * @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
* *
@ -22,7 +23,6 @@
*/ */
namespace OC\Preview; namespace OC\Preview;
use OCP\Files\File;
use OCP\Files\Node; use OCP\Files\Node;
use OCP\Files\Folder; use OCP\Files\Folder;
use OCP\Files\IAppData; use OCP\Files\IAppData;
@ -39,9 +39,6 @@ class Watcher {
/** @var IAppData */ /** @var IAppData */
private $appData; private $appData;
/** @var int[] */
private $toDelete = [];
/** /**
* Watcher constructor. * Watcher constructor.
* *
@ -58,47 +55,10 @@ class Watcher {
} }
try { try {
$folder = $this->appData->getFolder($node->getId()); $folder = $this->appData->getFolder((string)$node->getId());
$folder->delete(); $folder->delete();
} catch (NotFoundException $e) { } catch (NotFoundException $e) {
//Nothing to do //Nothing to do
} }
} }
public function preDelete(Node $node) {
// To avoid cycles
if ($this->toDelete !== []) {
return;
}
if ($node instanceof File) {
$this->toDelete[] = $node->getId();
return;
}
/** @var Folder $node */
$this->deleteFolder($node);
}
private function deleteFolder(Folder $folder) {
$nodes = $folder->getDirectoryListing();
foreach ($nodes as $node) {
if ($node instanceof File) {
$this->toDelete[] = $node->getId();
} else if ($node instanceof Folder) {
$this->deleteFolder($node);
}
}
}
public function postDelete(Node $node) {
foreach ($this->toDelete as $fid) {
try {
$folder = $this->appData->getFolder($fid);
$folder->delete();
} catch (NotFoundException $e) {
// continue
}
}
}
} }

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl> * @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
* *
@ -49,7 +50,7 @@ class WatcherConnector {
/** /**
* @return Watcher * @return Watcher
*/ */
private function getWatcher() { private function getWatcher(): Watcher {
return \OC::$server->query(Watcher::class); return \OC::$server->query(Watcher::class);
} }
@ -59,14 +60,6 @@ class WatcherConnector {
$this->root->listen('\OC\Files', 'postWrite', function (Node $node) { $this->root->listen('\OC\Files', 'postWrite', function (Node $node) {
$this->getWatcher()->postWrite($node); $this->getWatcher()->postWrite($node);
}); });
$this->root->listen('\OC\Files', 'preDelete', function (Node $node) {
$this->getWatcher()->preDelete($node);
});
$this->root->listen('\OC\Files', 'postDelete', function (Node $node) {
$this->getWatcher()->postDelete($node);
});
} }
} }
} }