summaryrefslogtreecommitdiffstats
path: root/lib/private/Preview
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-05-08 14:52:36 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2018-05-14 13:30:06 +0200
commit3e07c4f73a80bfa7e5de5a9e0074d2c7d35f18cc (patch)
treeddf0f30763553d08a23ad9e2320579bc145ebff4 /lib/private/Preview
parent253f962241ba7c96610f22e6940c31184650041d (diff)
downloadnextcloud-server-3e07c4f73a80bfa7e5de5a9e0074d2c7d35f18cc.tar.gz
nextcloud-server-3e07c4f73a80bfa7e5de5a9e0074d2c7d35f18cc.zip
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>
Diffstat (limited to 'lib/private/Preview')
-rw-r--r--lib/private/Preview/Watcher.php44
-rw-r--r--lib/private/Preview/WatcherConnector.php11
2 files changed, 4 insertions, 51 deletions
diff --git a/lib/private/Preview/Watcher.php b/lib/private/Preview/Watcher.php
index 8d091b84b0e..be462d9c935 100644
--- a/lib/private/Preview/Watcher.php
+++ b/lib/private/Preview/Watcher.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
*
@@ -22,7 +23,6 @@
*/
namespace OC\Preview;
-use OCP\Files\File;
use OCP\Files\Node;
use OCP\Files\Folder;
use OCP\Files\IAppData;
@@ -39,9 +39,6 @@ class Watcher {
/** @var IAppData */
private $appData;
- /** @var int[] */
- private $toDelete = [];
-
/**
* Watcher constructor.
*
@@ -58,47 +55,10 @@ class Watcher {
}
try {
- $folder = $this->appData->getFolder($node->getId());
+ $folder = $this->appData->getFolder((string)$node->getId());
$folder->delete();
} catch (NotFoundException $e) {
//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
- }
- }
- }
}
diff --git a/lib/private/Preview/WatcherConnector.php b/lib/private/Preview/WatcherConnector.php
index 4e6e786cec7..bf9e6c29e4f 100644
--- a/lib/private/Preview/WatcherConnector.php
+++ b/lib/private/Preview/WatcherConnector.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
*
@@ -49,7 +50,7 @@ class WatcherConnector {
/**
* @return Watcher
*/
- private function getWatcher() {
+ private function getWatcher(): Watcher {
return \OC::$server->query(Watcher::class);
}
@@ -59,14 +60,6 @@ class WatcherConnector {
$this->root->listen('\OC\Files', 'postWrite', function (Node $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);
- });
}
}
}