From 6d7c623e46bf5c614c6c8311afd6c8233210741d Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Fri, 13 Oct 2023 15:10:59 -0700 Subject: [PATCH] tq: refactor in root function Signed-off-by: Varun Patil --- lib/Db/TimelineQuery.php | 20 +------------------- lib/Db/TimelineQueryDays.php | 25 +++++++++++++++++++++++-- lib/Db/TimelineRoot.php | 13 ++----------- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/lib/Db/TimelineQuery.php b/lib/Db/TimelineQuery.php index 13f98f0e..6965785d 100644 --- a/lib/Db/TimelineQuery.php +++ b/lib/Db/TimelineQuery.php @@ -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; diff --git a/lib/Db/TimelineQueryDays.php b/lib/Db/TimelineQueryDays.php index 59cdc4f9..380713f5 100644 --- a/lib/Db/TimelineQueryDays.php +++ b/lib/Db/TimelineQueryDays.php @@ -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'); diff --git a/lib/Db/TimelineRoot.php b/lib/Db/TimelineRoot.php index a152fe54..a495b674 100644 --- a/lib/Db/TimelineRoot.php +++ b/lib/Db/TimelineRoot.php @@ -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)