tq: refactor in root function

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/877/head
Varun Patil 2023-10-13 15:10:59 -07:00
parent 8e79b769ed
commit 6d7c623e46
3 changed files with 26 additions and 32 deletions

View File

@ -28,7 +28,7 @@ class TimelineQuery
protected IDBConnection $connection;
protected IRequest $request;
protected ?TimelineRoot $_root = null;
protected ?TimelineRoot $_root = null; // cache
protected bool $_rootEmptyAllowed = false;
public function __construct(IDBConnection $connection, IRequest $request)
@ -37,24 +37,6 @@ class TimelineQuery
$this->request = $request;
}
public function root(?TimelineRoot $override = null): TimelineRoot
{
if (null !== $override) {
$this->_root = $override;
}
if (null === $this->_root) {
$this->_root = new TimelineRoot();
$this->_root->populate();
}
if (!$this->_rootEmptyAllowed && $this->_root->isEmpty()) {
throw new \Exception('No valid root folder found (.nomedia?)');
}
return $this->_root;
}
public function allowEmptyRoot(bool $value = true)
{
$this->_rootEmptyAllowed = $value;

View File

@ -159,8 +159,29 @@ trait TimelineQueryDays
bool $archive = false,
bool $hidden = false
): IQueryBuilder {
// This will throw if the root is illegally empty
$root = $this->root($root);
// Get the timeline root object
if (null == $root) {
// Cache the root object. This is fast when there are
// multiple queries such as days-day preloading BUT that
// means that any subsequent requests that don't match the
// same root MUST specify a separate root this function
if (null === $this->_root) {
$this->_root = new TimelineRoot();
// Populate the root using parameters from the request
$fs = \OC::$server->get(FsManager::class);
$fs->populateRoot($this->_root);
}
// Use the cached / newly populated root
$root = $this->_root;
}
// Check if the root is empty. This is illegal in most cases
// except for albums, which don't have a folder associated.
if (!$this->_rootEmptyAllowed && $root->isEmpty()) {
throw new \Exception('No valid root folder found (.nomedia?)');
}
// Join with memories
$baseOp = $query->expr()->eq('f.fileid', 'm.fileid');

View File

@ -18,14 +18,6 @@ class TimelineRoot
$this->folderPaths = [];
}
/**
* Populate the root with the current user's folders.
*/
public function populate()
{
\OC::$server->get(FsManager::class)->populateRoot($this);
}
/**
* Add a folder to the root.
*
@ -50,14 +42,13 @@ class TimelineRoot
// Add mountpoints recursively
public function addMountPoints()
{
$folders = [];
$manager = \OC\Files\Filesystem::getMountManager();
foreach ($this->folderPaths as $id => $folderPath) {
$mounts = \OC\Files\Filesystem::getMountManager()->findIn($folderPath);
$mounts = $manager->findIn($folderPath);
foreach ($mounts as $mount) {
$this->setFolder($mount->getStorageRootId(), null, $mount->getMountPoint());
}
}
$this->folderPaths += $folders;
}
public function excludePaths(array $paths)