nextcloud/apps/files/lib/Service/LivePhotosService.php
Carl Schwan fd3878448b
feat(filecache): Scale DB query created when deleting file from filecache
Instead of creating a CacheEntryRemovedEvent for each deleted files,
create a single CacheEntriesRemovedEvent which wrap multiple
CacheEntryRemovedEvent.

This allow listener to optimize the query they do when multiple files
are deleted at the same time (e.g. when deleting a folder).

Signed-off-by: Carl Schwan <carl.schwan@nextclound.com>
2026-01-28 16:07:57 +01:00

54 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files\Service;
use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException;
use OCP\FilesMetadata\IFilesMetadataManager;
class LivePhotosService {
public function __construct(
private IFilesMetadataManager $filesMetadataManager,
) {
}
/**
* Get the associated live photo for a given file id
*/
public function getLivePhotoPeerId(int $fileId): ?int {
try {
$metadata = $this->filesMetadataManager->getMetadata($fileId);
} catch (FilesMetadataNotFoundException $ex) {
return null;
}
if (!$metadata->hasKey('files-live-photo')) {
return null;
}
return (int)$metadata->getString('files-live-photo');
}
/**
* Get the associated live photo for multiple file ids
* @param int[] $fileIds
* @return int[]
*/
public function getLivePhotoPeerIds(array $fileIds): array {
$metadata = $this->filesMetadataManager->getMetadataForFiles($fileIds);
$peersIds = [];
foreach ($metadata as $item) {
if (!$item->hasKey('files-live-photo')) {
continue;
}
$peersIds[] = (int)$item->getString('files-live-photo');
}
return $peersIds;
}
}