diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/lib/Connector/Sabre/Directory.php | 4 | ||||
-rw-r--r-- | apps/dav/lib/Connector/Sabre/File.php | 16 | ||||
-rw-r--r-- | apps/dav/lib/Connector/Sabre/FilesPlugin.php | 127 | ||||
-rw-r--r-- | apps/dav/lib/Files/FileSearchBackend.php | 23 | ||||
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php | 3 | ||||
-rw-r--r-- | apps/files/lib/Command/Scan.php | 7 | ||||
-rw-r--r-- | apps/files_trashbin/lib/Trashbin.php | 4 |
7 files changed, 61 insertions, 123 deletions
diff --git a/apps/dav/lib/Connector/Sabre/Directory.php b/apps/dav/lib/Connector/Sabre/Directory.php index 20202d83689..ab321a363a2 100644 --- a/apps/dav/lib/Connector/Sabre/Directory.php +++ b/apps/dav/lib/Connector/Sabre/Directory.php @@ -34,7 +34,6 @@ namespace OCA\DAV\Connector\Sabre; use OC\Files\Mount\MoveableMount; use OC\Files\View; -use OC\Metadata\FileMetadata; use OCA\DAV\AppInfo\Application; use OCA\DAV\Connector\Sabre\Exception\FileLocked; use OCA\DAV\Connector\Sabre\Exception\Forbidden; @@ -70,9 +69,6 @@ class Directory extends \OCA\DAV\Connector\Sabre\Node implements \Sabre\DAV\ICol private ?array $quotaInfo = null; private ?CachingTree $tree = null; - /** @var array<string, array<int, FileMetadata>> */ - private array $metadata = []; - /** * Sets up the node, expects a full path name */ diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index 8ce8c843a66..f188490fd93 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -43,7 +43,6 @@ use OC\AppFramework\Http\Request; use OC\Files\Filesystem; use OC\Files\Stream\HashWrapper; use OC\Files\View; -use OC\Metadata\FileMetadata; use OCA\DAV\AppInfo\Application; use OCA\DAV\Connector\Sabre\Exception\BadGateway; use OCA\DAV\Connector\Sabre\Exception\EntityTooLarge; @@ -81,9 +80,6 @@ class File extends Node implements IFile { protected IRequest $request; protected IL10N $l10n; - /** @var array<string, FileMetadata> */ - private array $metadata = []; - /** * Sets up the node, expects a full path name * @@ -796,16 +792,4 @@ class File extends Node implements IFile { public function getNode(): \OCP\Files\File { return $this->node; } - - public function getMetadata(string $group): FileMetadata { - return $this->metadata[$group]; - } - - public function setMetadata(string $group, FileMetadata $metadata): void { - $this->metadata[$group] = $metadata; - } - - public function hasMetadata(string $group) { - return array_key_exists($group, $this->metadata); - } } diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index 9319327d094..cd188872019 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -35,19 +35,20 @@ namespace OCA\DAV\Connector\Sabre; use OC\AppFramework\Http\Request; -use OC\Metadata\IMetadataManager; +use OC\FilesMetadata\Model\MetadataValueWrapper; use OCP\Constants; use OCP\Files\ForbiddenException; use OCP\Files\StorageNotAvailableException; +use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException; +use OCP\FilesMetadata\IFilesMetadataManager; +use OCP\FilesMetadata\Model\IMetadataValueWrapper; use OCP\IConfig; use OCP\IPreview; use OCP\IRequest; use OCP\IUserSession; -use Psr\Log\LoggerInterface; use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\NotFound; use Sabre\DAV\IFile; -use Sabre\DAV\INode; use Sabre\DAV\PropFind; use Sabre\DAV\PropPatch; use Sabre\DAV\Server; @@ -86,17 +87,6 @@ class FilesPlugin extends ServerPlugin { public const SUBFOLDER_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-folder-count'; public const SUBFILE_COUNT_PROPERTYNAME = '{http://nextcloud.org/ns}contained-file-count'; public const FILE_METADATA_PREFIX = '{http://nextcloud.org/ns}metadata-'; - public const FILE_METADATA_SIZE = '{http://nextcloud.org/ns}file-metadata-size'; - public const FILE_METADATA_GPS = '{http://nextcloud.org/ns}file-metadata-gps'; - - public const ALL_METADATA_PROPS = [ - self::FILE_METADATA_SIZE => 'size', - self::FILE_METADATA_GPS => 'gps', - ]; - public const METADATA_MIMETYPES = [ - 'size' => 'image', - 'gps' => 'image', - ]; /** Reference to main server object */ private ?Server $server = null; @@ -434,31 +424,6 @@ class FilesPlugin extends ServerPlugin { $propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function () use ($node) { return $node->getFileInfo()->getUploadTime(); }); - - if ($this->config->getSystemValueBool('enable_file_metadata', true)) { - foreach (self::ALL_METADATA_PROPS as $prop => $meta) { - $propFind->handle($prop, function () use ($node, $meta) { - if ($node->getFileInfo()->getMimePart() !== self::METADATA_MIMETYPES[$meta]) { - return []; - } - - if ($node->hasMetadata($meta)) { - $metadata = $node->getMetadata($meta); - } else { - // This code path should not be called since we try to preload - // the metadata when loading the folder or the search results - // in one go - $metadataManager = \OC::$server->get(IMetadataManager::class); - $metadata = $metadataManager->fetchMetadataFor($meta, [$node->getId()])[$node->getId()]; - - // TODO would be nice to display this in the profiler... - \OC::$server->get(LoggerInterface::class)->debug('Inefficient fetching of metadata'); - } - - return $metadata->getValue(); - }); - } - } } if ($node instanceof Directory) { @@ -472,39 +437,6 @@ class FilesPlugin extends ServerPlugin { $requestProperties = $propFind->getRequestedProperties(); - $requestedMetaData = []; - foreach ($requestProperties as $requestProperty) { - if (isset(self::ALL_METADATA_PROPS[$requestProperty])) { - $requestedMetaData[] = self::ALL_METADATA_PROPS[$requestProperty]; - } - } - if ( - $this->config->getSystemValueBool('enable_file_metadata', true) && - $propFind->getDepth() === 1 && - $requestedMetaData - ) { - $children = $node->getChildren(); - // Preloading of the metadata - - /** @var IMetaDataManager $metadataManager */ - $metadataManager = \OC::$server->get(IMetadataManager::class); - - foreach ($requestedMetaData as $requestedMeta) { - $relevantMimeType = self::METADATA_MIMETYPES[$requestedMeta]; - $childrenForMeta = array_filter($children, function (INode $child) use ($relevantMimeType) { - return $child instanceof File && $child->getFileInfo()->getMimePart() === $relevantMimeType; - }); - $fileIds = array_map(function (File $child) { - return $child->getFileInfo()->getId(); - }, $childrenForMeta); - $preloadedMetadata = $metadataManager->fetchMetadataFor($requestedMeta, $fileIds); - - foreach ($childrenForMeta as $child) { - $child->setMetadata($requestedMeta, $preloadedMetadata[$child->getFileInfo()->getId()]); - } - } - } - if (in_array(self::SUBFILE_COUNT_PROPERTYNAME, $requestProperties, true) || in_array(self::SUBFOLDER_COUNT_PROPERTYNAME, $requestProperties, true)) { $nbFiles = 0; @@ -590,6 +522,57 @@ class FilesPlugin extends ServerPlugin { $node->setCreationTime((int) $time); return true; }); + + + /** @var IFilesMetadataManager */ + $filesMetadataManager = \OCP\Server::get(IFilesMetadataManager::class); + $knownMetadata = $filesMetadataManager->getKnownMetadata(); + + foreach ($propPatch->getRemainingMutations() as $mutation) { + if (!str_starts_with($mutation, self::FILE_METADATA_PREFIX)) { + continue; + } + + $propPatch->handle($mutation, function (mixed $value) use ($knownMetadata, $node, $mutation, $filesMetadataManager): bool { + $metadata = $filesMetadataManager->getMetadata((int)$node->getFileId(), true); + $metadataKey = substr($mutation, strlen(self::FILE_METADATA_PREFIX)); + + // If the metadata is unknown, it defaults to string. + try { + $type = $knownMetadata->getType($metadataKey); + } catch (FilesMetadataNotFoundException) { + $type = IMetadataValueWrapper::TYPE_STRING; + } + + switch ($type) { + case IMetadataValueWrapper::TYPE_STRING: + $metadata->setString($metadataKey, $value, $knownMetadata->isIndex($metadataKey)); + break; + case IMetadataValueWrapper::TYPE_INT: + $metadata->setInt($metadataKey, $value, $knownMetadata->isIndex($metadataKey)); + break; + case IMetadataValueWrapper::TYPE_FLOAT: + $metadata->setFloat($metadataKey, $value); + break; + case IMetadataValueWrapper::TYPE_BOOL: + $metadata->setBool($metadataKey, $value, $knownMetadata->isIndex($metadataKey)); + break; + case IMetadataValueWrapper::TYPE_ARRAY: + $metadata->setArray($metadataKey, $value); + break; + case IMetadataValueWrapper::TYPE_STRING_LIST: + $metadata->setStringList($metadataKey, $value, $knownMetadata->isIndex($metadataKey)); + break; + case IMetadataValueWrapper::TYPE_INT_LIST: + $metadata->setIntList($metadataKey, $value, $knownMetadata->isIndex($metadataKey)); + break; + } + + $filesMetadataManager->saveMetadata($metadata); + return true; + }); + } + /** * Disable modification of the displayname property for files and * folders via PROPPATCH. See PROPFIND for more information. diff --git a/apps/dav/lib/Files/FileSearchBackend.php b/apps/dav/lib/Files/FileSearchBackend.php index 658ad34ec32..b158fde857c 100644 --- a/apps/dav/lib/Files/FileSearchBackend.php +++ b/apps/dav/lib/Files/FileSearchBackend.php @@ -31,7 +31,6 @@ use OC\Files\Search\SearchComparison; use OC\Files\Search\SearchOrder; use OC\Files\Search\SearchQuery; use OC\Files\View; -use OC\Metadata\IMetadataManager; use OCA\DAV\Connector\Sabre\CachingTree; use OCA\DAV\Connector\Sabre\Directory; use OCA\DAV\Connector\Sabre\FilesPlugin; @@ -115,7 +114,6 @@ class FileSearchBackend implements ISearchBackend { new SearchPropertyDefinition(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME, true, false, false), new SearchPropertyDefinition(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME, true, false, false), new SearchPropertyDefinition(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, true, false, false, SearchPropertyDefinition::DATATYPE_BOOLEAN), - new SearchPropertyDefinition(FilesPlugin::FILE_METADATA_SIZE, true, false, false, SearchPropertyDefinition::DATATYPE_STRING), new SearchPropertyDefinition(FilesPlugin::FILEID_PROPERTYNAME, true, false, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), ]; @@ -152,27 +150,6 @@ class FileSearchBackend implements ISearchBackend { * @param string[] $requestProperties */ public function preloadPropertyFor(array $nodes, array $requestProperties): void { - if (in_array(FilesPlugin::FILE_METADATA_SIZE, $requestProperties, true)) { - // Preloading of the metadata - $fileIds = []; - foreach ($nodes as $node) { - /** @var \OCP\Files\Node|\OCA\DAV\Connector\Sabre\Node $node */ - if (str_starts_with($node->getFileInfo()->getMimeType(), 'image/')) { - /** @var \OCA\DAV\Connector\Sabre\File $node */ - $fileIds[] = $node->getFileInfo()->getId(); - } - } - /** @var IMetaDataManager $metadataManager */ - $metadataManager = \OC::$server->get(IMetadataManager::class); - $preloadedMetadata = $metadataManager->fetchMetadataFor('size', $fileIds); - foreach ($nodes as $node) { - /** @var \OCP\Files\Node|\OCA\DAV\Connector\Sabre\Node $node */ - if (str_starts_with($node->getFileInfo()->getMimeType(), 'image/')) { - /** @var \OCA\DAV\Connector\Sabre\File $node */ - $node->setMetadata('size', $preloadedMetadata[$node->getFileInfo()->getId()]); - } - } - } } /** diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php index 5e638bbcd89..32573a68f73 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php @@ -57,6 +57,8 @@ use Test\TestCase; * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. + * + * @group DB */ class FilesPluginTest extends TestCase { public const GETETAG_PROPERTYNAME = FilesPlugin::GETETAG_PROPERTYNAME; @@ -424,6 +426,7 @@ class FilesPluginTest extends TestCase { self::CREATIONDATE_PROPERTYNAME => $testCreationDate, ]); + $this->plugin->handleUpdateProperties( '/dummypath', $propPatch diff --git a/apps/files/lib/Command/Scan.php b/apps/files/lib/Command/Scan.php index b1fc25bfe9b..7cdaf75e9bc 100644 --- a/apps/files/lib/Command/Scan.php +++ b/apps/files/lib/Command/Scan.php @@ -40,12 +40,10 @@ use OC\DB\Connection; use OC\DB\ConnectionAdapter; use OC\FilesMetadata\FilesMetadataManager; use OC\ForbiddenException; -use OC\Metadata\MetadataManager; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Events\FileCacheUpdated; use OCP\Files\Events\NodeAddedToCache; use OCP\Files\Events\NodeRemovedFromCache; -use OCP\Files\File; use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountPoint; use OCP\Files\NotFoundException; @@ -71,7 +69,6 @@ class Scan extends Base { public function __construct( private IUserManager $userManager, private IRootFolder $rootFolder, - private MetadataManager $metadataManager, private FilesMetadataManager $filesMetadataManager, private IEventDispatcher $eventDispatcher, private LoggerInterface $logger, @@ -141,10 +138,6 @@ class Scan extends Base { $this->abortIfInterrupted(); if ($scanMetadata) { $node = $this->rootFolder->get($path); - if ($node instanceof File) { - $this->metadataManager->generateMetadata($node, false); - } - $this->filesMetadataManager->refreshMetadata( $node, IFilesMetadataManager::PROCESS_LIVE | IFilesMetadataManager::PROCESS_BACKGROUND diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php index 90f74e51e81..94ad77ac1c5 100644 --- a/apps/files_trashbin/lib/Trashbin.php +++ b/apps/files_trashbin/lib/Trashbin.php @@ -59,6 +59,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; +use OCP\FilesMetadata\IFilesMetadataManager; use OCP\IConfig; use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; @@ -993,7 +994,8 @@ class Trashbin { $query = new CacheQueryBuilder( \OC::$server->getDatabaseConnection(), \OC::$server->getSystemConfig(), - \OC::$server->get(LoggerInterface::class) + \OC::$server->get(LoggerInterface::class), + \OC::$server->get(IFilesMetadataManager::class), ); $normalizedParentPath = ltrim(Filesystem::normalizePath(dirname('files_trashbin/versions/'. $filename)), '/'); $parentId = $cache->getId($normalizedParentPath); |