Browse Source

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>
tags/v14.0.0beta1
Roeland Jago Douma 6 years ago
parent
commit
3e07c4f73a
No account linked to committer's email address
2 changed files with 4 additions and 51 deletions
  1. 2
    42
      lib/private/Preview/Watcher.php
  2. 2
    9
      lib/private/Preview/WatcherConnector.php

+ 2
- 42
lib/private/Preview/Watcher.php View File

@@ -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
}
}
}
}

+ 2
- 9
lib/private/Preview/WatcherConnector.php View File

@@ -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);
});
}
}
}

Loading…
Cancel
Save