Skip to content

Commit ce31914

Browse files
committed
Remove inefficient fed share scanner
Remove scanAll which relies on the "shareinfo" endpoint that returns the full cache tree. The latter can become big for big shares and result in timeouts. Furthermode, the full tree would be retrieved again for each and every detected change which can become expensive quickly. Signed-off-by: Vincent Petry <vincent@nextcloud.com>
1 parent 91c7efa commit ce31914

File tree

2 files changed

+0
-82
lines changed

2 files changed

+0
-82
lines changed

apps/files_sharing/lib/External/Scanner.php

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,11 @@
2929
use OCP\Files\NotFoundException;
3030
use OCP\Files\StorageInvalidException;
3131
use OCP\Files\StorageNotAvailableException;
32-
use OCP\Http\Client\LocalServerException;
33-
use Psr\Log\LoggerInterface;
3432

3533
class Scanner extends \OC\Files\Cache\Scanner {
3634
/** @var \OCA\Files_Sharing\External\Storage */
3735
protected $storage;
3836

39-
/** {@inheritDoc} */
40-
public function scan($path, $recursive = self::SCAN_RECURSIVE, $reuse = -1, $lock = true) {
41-
try {
42-
if (!$this->storage->remoteIsOwnCloud()) {
43-
return parent::scan($path, $recursive, $reuse, $lock);
44-
}
45-
} catch (LocalServerException $e) {
46-
// Scanner doesn't have dependency injection
47-
\OC::$server->get(LoggerInterface::class)
48-
->warning('Trying to scan files inside invalid external storage: ' . $this->storage->getRemote() . ' for mountpoint ' . $this->storage->getMountPoint() . ' and id ' . $this->storage->getId());
49-
return;
50-
}
51-
52-
$this->scanAll();
53-
}
54-
5537
/**
5638
* Scan a single file and store it in the cache.
5739
* If an exception happened while accessing the external storage,
@@ -81,56 +63,4 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData =
8163
$this->storage->checkStorageAvailability();
8264
}
8365
}
84-
85-
/**
86-
* Checks the remote share for changes.
87-
* If changes are available, scan them and update
88-
* the cache.
89-
* @throws NotFoundException
90-
* @throws StorageInvalidException
91-
* @throws \Exception
92-
*/
93-
public function scanAll() {
94-
try {
95-
$data = $this->storage->getShareInfo();
96-
} catch (\Exception $e) {
97-
$this->storage->checkStorageAvailability();
98-
throw new \Exception(
99-
'Error while scanning remote share: "' .
100-
$this->storage->getRemote() . '" ' .
101-
$e->getMessage()
102-
);
103-
}
104-
if ($data['status'] === 'success') {
105-
$this->addResult($data['data'], '');
106-
} else {
107-
throw new \Exception(
108-
'Error while scanning remote share: "' .
109-
$this->storage->getRemote() . '"'
110-
);
111-
}
112-
}
113-
114-
/**
115-
* @param array $data
116-
* @param string $path
117-
*/
118-
private function addResult($data, $path) {
119-
$id = $this->cache->put($path, $data);
120-
if (isset($data['children'])) {
121-
$children = [];
122-
foreach ($data['children'] as $child) {
123-
$children[$child['name']] = true;
124-
$this->addResult($child, ltrim($path . '/' . $child['name'], '/'));
125-
}
126-
127-
$existingCache = $this->cache->getFolderContentsById($id);
128-
foreach ($existingCache as $existingChild) {
129-
// if an existing child is not in the new data, remove it
130-
if (!isset($children[$existingChild['name']])) {
131-
$this->cache->remove(ltrim($path . '/' . $existingChild['name'], '/'));
132-
}
133-
}
134-
}
135-
}
13666
}

apps/files_sharing/tests/External/ScannerTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ protected function setUp(): void {
5050
$this->scanner = new Scanner($this->storage);
5151
}
5252

53-
public function testScanAll() {
54-
$this->storage->expects($this->any())
55-
->method('getShareInfo')
56-
->willReturn(['status' => 'success', 'data' => []]);
57-
58-
// FIXME add real tests, we are currently only checking for
59-
// Declaration of OCA\Files_Sharing\External\Scanner::*() should be
60-
// compatible with OC\Files\Cache\Scanner::*()
61-
$this->scanner->scanAll();
62-
$this->addToAssertionCount(1);
63-
}
64-
6553
public function testScan() {
6654
$this->storage->expects($this->any())
6755
->method('getShareInfo')

0 commit comments

Comments
 (0)