Skip to content

Commit 3e07c4f

Browse files
committed
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>
1 parent 253f962 commit 3e07c4f

2 files changed

Lines changed: 4 additions & 51 deletions

File tree

lib/private/Preview/Watcher.php

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
/**
34
* @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
45
*
@@ -22,7 +23,6 @@
2223
*/
2324
namespace OC\Preview;
2425

25-
use OCP\Files\File;
2626
use OCP\Files\Node;
2727
use OCP\Files\Folder;
2828
use OCP\Files\IAppData;
@@ -39,9 +39,6 @@ class Watcher {
3939
/** @var IAppData */
4040
private $appData;
4141

42-
/** @var int[] */
43-
private $toDelete = [];
44-
4542
/**
4643
* Watcher constructor.
4744
*
@@ -58,47 +55,10 @@ public function postWrite(Node $node) {
5855
}
5956

6057
try {
61-
$folder = $this->appData->getFolder($node->getId());
58+
$folder = $this->appData->getFolder((string)$node->getId());
6259
$folder->delete();
6360
} catch (NotFoundException $e) {
6461
//Nothing to do
6562
}
6663
}
67-
68-
public function preDelete(Node $node) {
69-
// To avoid cycles
70-
if ($this->toDelete !== []) {
71-
return;
72-
}
73-
74-
if ($node instanceof File) {
75-
$this->toDelete[] = $node->getId();
76-
return;
77-
}
78-
79-
/** @var Folder $node */
80-
$this->deleteFolder($node);
81-
}
82-
83-
private function deleteFolder(Folder $folder) {
84-
$nodes = $folder->getDirectoryListing();
85-
foreach ($nodes as $node) {
86-
if ($node instanceof File) {
87-
$this->toDelete[] = $node->getId();
88-
} else if ($node instanceof Folder) {
89-
$this->deleteFolder($node);
90-
}
91-
}
92-
}
93-
94-
public function postDelete(Node $node) {
95-
foreach ($this->toDelete as $fid) {
96-
try {
97-
$folder = $this->appData->getFolder($fid);
98-
$folder->delete();
99-
} catch (NotFoundException $e) {
100-
// continue
101-
}
102-
}
103-
}
10464
}

lib/private/Preview/WatcherConnector.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
/**
34
* @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
45
*
@@ -49,7 +50,7 @@ public function __construct(IRootFolder $root,
4950
/**
5051
* @return Watcher
5152
*/
52-
private function getWatcher() {
53+
private function getWatcher(): Watcher {
5354
return \OC::$server->query(Watcher::class);
5455
}
5556

@@ -59,14 +60,6 @@ public function connectWatcher() {
5960
$this->root->listen('\OC\Files', 'postWrite', function (Node $node) {
6061
$this->getWatcher()->postWrite($node);
6162
});
62-
63-
$this->root->listen('\OC\Files', 'preDelete', function (Node $node) {
64-
$this->getWatcher()->preDelete($node);
65-
});
66-
67-
$this->root->listen('\OC\Files', 'postDelete', function (Node $node) {
68-
$this->getWatcher()->postDelete($node);
69-
});
7063
}
7164
}
7265
}

0 commit comments

Comments
 (0)