server/lib/private/Preview/WatcherConnector.php
Roeland Jago Douma 3e07c4f73a
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>
2018-05-14 13:30:06 +02:00

65 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Roeland Jago Douma <roeland@famdouma.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Preview;
use OC\SystemConfig;
use OCP\Files\Node;
use OCP\Files\IRootFolder;
class WatcherConnector {
/** @var IRootFolder */
private $root;
/** @var SystemConfig */
private $config;
/**
* WatcherConnector constructor.
*
* @param IRootFolder $root
* @param SystemConfig $config
*/
public function __construct(IRootFolder $root,
SystemConfig $config) {
$this->root = $root;
$this->config = $config;
}
/**
* @return Watcher
*/
private function getWatcher(): Watcher {
return \OC::$server->query(Watcher::class);
}
public function connectWatcher() {
// Do not connect if we are not setup yet!
if ($this->config->getValue('instanceid', null) !== null) {
$this->root->listen('\OC\Files', 'postWrite', function (Node $node) {
$this->getWatcher()->postWrite($node);
});
}
}
}