Skip to content

Commit 5ffb826

Browse files
authored
Merge pull request #31902 from nextcloud/backport/31713/stable23
[stable23] Federated share performance improvements
2 parents 0b7cc5f + 8b8f0e6 commit 5ffb826

7 files changed

Lines changed: 55 additions & 6 deletions

File tree

apps/files_sharing/lib/External/Storage.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@
4242
use OCP\Federation\ICloudId;
4343
use OCP\Files\NotFoundException;
4444
use OCP\Files\Storage\IDisableEncryptionStorage;
45+
use OCP\Files\Storage\IReliableEtagStorage;
4546
use OCP\Files\StorageInvalidException;
4647
use OCP\Files\StorageNotAvailableException;
4748
use OCP\Http\Client\LocalServerException;
4849

49-
class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage {
50+
class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, IReliableEtagStorage {
5051
/** @var ICloudId */
5152
private $cloudId;
5253
/** @var string */
@@ -372,6 +373,8 @@ public function getPermissions($path) {
372373
} elseif (isset($response['{http://open-cloud-mesh.org/ns}share-permissions'])) {
373374
// permissions provided by the OCM API
374375
$permissions = $this->ocmPermissions2ncPermissions($response['{http://open-collaboration-services.org/ns}share-permissions'], $path);
376+
} elseif (isset($response['{http://owncloud.org/ns}permissions'])) {
377+
return $this->parsePermissions($response['{http://owncloud.org/ns}permissions']);
375378
} else {
376379
// use default permission if remote server doesn't provide the share permissions
377380
$permissions = $this->getDefaultPermissions($path);
@@ -432,4 +435,8 @@ protected function getDefaultPermissions($path) {
432435

433436
return $permissions;
434437
}
438+
439+
public function free_space($path) {
440+
return parent::free_space("");
441+
}
435442
}

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@
322322
'OCP\\Files\\Storage\\IDisableEncryptionStorage' => $baseDir . '/lib/public/Files/Storage/IDisableEncryptionStorage.php',
323323
'OCP\\Files\\Storage\\ILockingStorage' => $baseDir . '/lib/public/Files/Storage/ILockingStorage.php',
324324
'OCP\\Files\\Storage\\INotifyStorage' => $baseDir . '/lib/public/Files/Storage/INotifyStorage.php',
325+
'OCP\\Files\\Storage\\IReliableEtagStorage' => $baseDir . '/lib/public/Files/Storage/IReliableEtagStorage.php',
325326
'OCP\\Files\\Storage\\IStorage' => $baseDir . '/lib/public/Files/Storage/IStorage.php',
326327
'OCP\\Files\\Storage\\IStorageFactory' => $baseDir . '/lib/public/Files/Storage/IStorageFactory.php',
327328
'OCP\\Files\\Storage\\IWriteStreamStorage' => $baseDir . '/lib/public/Files/Storage/IWriteStreamStorage.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
351351
'OCP\\Files\\Storage\\IDisableEncryptionStorage' => __DIR__ . '/../../..' . '/lib/public/Files/Storage/IDisableEncryptionStorage.php',
352352
'OCP\\Files\\Storage\\ILockingStorage' => __DIR__ . '/../../..' . '/lib/public/Files/Storage/ILockingStorage.php',
353353
'OCP\\Files\\Storage\\INotifyStorage' => __DIR__ . '/../../..' . '/lib/public/Files/Storage/INotifyStorage.php',
354+
'OCP\\Files\\Storage\\IReliableEtagStorage' => __DIR__ . '/../../..' . '/lib/public/Files/Storage/IReliableEtagStorage.php',
354355
'OCP\\Files\\Storage\\IStorage' => __DIR__ . '/../../..' . '/lib/public/Files/Storage/IStorage.php',
355356
'OCP\\Files\\Storage\\IStorageFactory' => __DIR__ . '/../../..' . '/lib/public/Files/Storage/IStorageFactory.php',
356357
'OCP\\Files\\Storage\\IWriteStreamStorage' => __DIR__ . '/../../..' . '/lib/public/Files/Storage/IWriteStreamStorage.php',

lib/private/Files/Cache/Propagator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
* along with this program. If not, see <http://www.gnu.org/licenses/>
2222
*
2323
*/
24+
2425
namespace OC\Files\Cache;
2526

2627
use OCP\DB\QueryBuilder\IQueryBuilder;
2728
use OCP\Files\Cache\IPropagator;
29+
use OCP\Files\Storage\IReliableEtagStorage;
2830
use OCP\IDBConnection;
2931

3032
/**
@@ -91,9 +93,11 @@ public function propagateChange($internalPath, $time, $sizeDifference = 0) {
9193

9294
$builder->update('filecache')
9395
->set('mtime', $builder->func()->greatest('mtime', $builder->createNamedParameter((int)$time, IQueryBuilder::PARAM_INT)))
94-
->set('etag', $builder->createNamedParameter($etag, IQueryBuilder::PARAM_STR))
9596
->where($builder->expr()->eq('storage', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)))
9697
->andWhere($builder->expr()->in('path_hash', $hashParams));
98+
if (!$this->storage->instanceOfStorage(IReliableEtagStorage::class)) {
99+
$builder->set('etag', $builder->createNamedParameter($etag, IQueryBuilder::PARAM_STR));
100+
}
97101

98102
$builder->execute();
99103

@@ -141,7 +145,7 @@ private function addToBatch($internalPath, $time, $sizeDifference) {
141145
$this->batch[$internalPath] = [
142146
'hash' => md5($internalPath),
143147
'time' => $time,
144-
'size' => $sizeDifference
148+
'size' => $sizeDifference,
145149
];
146150
} else {
147151
$this->batch[$internalPath]['size'] += $sizeDifference;

lib/private/Files/Cache/Scanner.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
use OC\Hooks\BasicEmitter;
4343
use OCP\Files\Cache\IScanner;
4444
use OCP\Files\ForbiddenException;
45+
use OCP\Files\Storage\IReliableEtagStorage;
4546
use OCP\ILogger;
4647
use OCP\Lock\ILockingProvider;
4748

@@ -209,7 +210,7 @@ public function scanFile($file, $reuseExisting = 0, $parentId = -1, $cacheData =
209210
if (($reuseExisting & self::REUSE_SIZE) && ($data['size'] === -1)) {
210211
$data['size'] = $cacheData['size'];
211212
}
212-
if ($reuseExisting & self::REUSE_ETAG) {
213+
if ($reuseExisting & self::REUSE_ETAG && !$this->storage->instanceOfStorage(IReliableEtagStorage::class)) {
213214
$data['etag'] = $etag;
214215
}
215216
}

lib/private/Files/Storage/DAV.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ protected function propfind($path) {
275275
'{http://open-collaboration-services.org/ns}share-permissions',
276276
'{DAV:}resourcetype',
277277
'{DAV:}getetag',
278+
'{DAV:}quota-available-bytes',
278279
]
279280
);
280281
$this->statCache->set($path, $response);
@@ -428,8 +429,7 @@ public function free_space($path) {
428429
$this->init();
429430
$path = $this->cleanPath($path);
430431
try {
431-
// TODO: cacheable ?
432-
$response = $this->client->propfind($this->encodePath($path), ['{DAV:}quota-available-bytes']);
432+
$response = $this->propfind($path);
433433
if ($response === false) {
434434
return FileInfo::SPACE_UNKNOWN;
435435
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace OCP\Files\Storage;
25+
26+
/**
27+
* Marks a storage as providing reliable etags according to expected behavior of etags within nextcloud:
28+
*
29+
* - Etag are stable as long as no changes are made to the files
30+
* - Changes inside a folder cause etag changes of the parent folders
31+
*
32+
* @since 23.0.4
33+
*/
34+
interface IReliableEtagStorage extends IStorage {
35+
}

0 commit comments

Comments
 (0)