Dear Nextcould developer community,
I have a big list of fileId’s and need to get the remaining Information for those file. Currently I’m doing
foreach ($fileIds as $fileId) {
$cacheEntry = $cache->get($fileId);
if ($cacheEntry) {
// this path is relative to owner's storage
//$path = $cacheEntry->getPath();
//but we want it relative to current user's storage
$files = $folder->getById($fileId);
if (empty($files)) {
continue;
}
$file = array_shift($files);
if ($file === null) {
continue;
}
$path = $userFolder->getRelativePath($file->getPath());
$isIgnored = false;
foreach ($ignoredPaths as $ignoredPath) {
if (str_starts_with($path, $ignoredPath)) {
$isIgnored = true;
break;
}
}
if (!$isIgnored) {
$isRoot = $file === $userFolder;
$file_object = new \stdClass();
$file_object->fileId = $fileId;
$file_object->fileid = $file_object->fileId;
$file_object->basename = $isRoot ? '' : $file->getName();
$file_object->filename = $this->normalizePath($path);
$file_object->etag = $cacheEntry->getEtag();
//Not working for NC21 as Viewer requires String representation of permissions
// $file_object->permissions = $file->getPermissions();
$file_object->type = $file->getType();
$file_object->mime = $file->getMimetype();
$file_object->lastmod = $file->getMTime();
$file_object->size = $file->getSize();
$file_object->path = $path;
$file_object->isReadable = $file->isReadable();
$file_object->isUpdateable = $file->isUpdateable();
$file_object->isShareable = $file->isShareable();
$file_object->isDeletable = $file->isDeletable();
$file_object->hasPreview = in_array($cacheEntry->getMimeType(), $previewEnableMimetypes);
$filesById[] = $file_object;
}
}
}
This results into at-least one DB query per FileId. I have multipe thousands to multiple 10 thousands and therefore lots of Queries are executed.
What is the proper way to reduce those Queries? Can I directly query the filecache table?
Is there any function like getFilesByIds ?
Best,
Arne