From 9c77a8f0c8376e56a6ce41d3b9cf215f02f745a4 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 13 Sep 2022 11:25:24 -0700 Subject: [PATCH] Fix category filter for shared folders --- lib/Db/TimelineQueryDay.php | 7 +++---- lib/Db/TimelineQueryFilters.php | 34 ++++++++++++++++----------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/lib/Db/TimelineQueryDay.php b/lib/Db/TimelineQueryDay.php index 0134252b..55919c7c 100644 --- a/lib/Db/TimelineQueryDay.php +++ b/lib/Db/TimelineQueryDay.php @@ -6,7 +6,6 @@ namespace OCA\Memories\Db; use OCA\Memories\Exif; use OCP\IConfig; use OCP\IDBConnection; -use OCP\ITags; use OCP\DB\QueryBuilder\IQueryBuilder; trait TimelineQueryDay { @@ -24,10 +23,10 @@ trait TimelineQueryDay { unset($row["isvideo"]); } - if ($row["category"] === ITags::TAG_FAVORITE) { + if ($row["categoryid"]) { $row["isfavorite"] = 1; } - unset($row["category"]); + unset($row["categoryid"]); } return $day; } @@ -40,7 +39,7 @@ trait TimelineQueryDay { $whereFilecache ) { // Get all entries also present in filecache - $query->select('m.fileid', 'f.etag', 'm.isvideo', 'vc.category') + $query->select('m.fileid', 'f.etag', 'm.isvideo', 'vco.categoryid') ->from('memories', 'm') ->innerJoin('m', 'filecache', 'f', $query->expr()->andX( diff --git a/lib/Db/TimelineQueryFilters.php b/lib/Db/TimelineQueryFilters.php index 3c6bd345..44e5e670 100644 --- a/lib/Db/TimelineQueryFilters.php +++ b/lib/Db/TimelineQueryFilters.php @@ -8,31 +8,29 @@ use OCP\ITags; trait TimelineQueryFilters { public function transformFavoriteFilter(IQueryBuilder $query, string $userId) { - // Inner join will filter only the favorites - $query->innerJoin('m', 'vcategory_to_object', 'fvco', $query->expr()->eq('fvco.objid', 'm.fileid')); - - // Get the favorites category only - $query->innerJoin('fvco', 'vcategory', 'fvc', $query->expr()->andX( - $query->expr()->eq('fvc.id', 'fvco.categoryid'), - $query->expr()->eq('fvc.type', $query->createNamedParameter("files")), - $query->expr()->eq('fvc.uid', $query->createNamedParameter($userId)), - $query->expr()->eq('fvc.category', $query->createNamedParameter(ITags::TAG_FAVORITE)), + $query->innerJoin('m', 'vcategory_to_object', 'vcoi', $query->expr()->andX( + $query->expr()->eq('vcoi.objid', 'm.fileid'), + $query->expr()->in('vcoi.categoryid', $this->getFavoriteVCategoryFun($query, $userId)), )); } public function addFavoriteTag(IQueryBuilder $query, string $userId) { - // Inner join will filter only the favorites - $query->leftJoin('m', 'vcategory_to_object', 'vco', $query->expr()->eq('vco.objid', 'm.fileid')); - - // Get the favorites category only - $query->leftJoin('vco', 'vcategory', 'vc', $query->expr()->andX( - $query->expr()->eq('vc.id', 'vco.categoryid'), - $query->expr()->eq('vc.type', $query->createNamedParameter("files")), - $query->expr()->eq('vc.uid', $query->createNamedParameter($userId)), - $query->expr()->eq('vc.category', $query->createNamedParameter(ITags::TAG_FAVORITE)), + $query->leftJoin('m', 'vcategory_to_object', 'vco', $query->expr()->andX( + $query->expr()->eq('vco.objid', 'm.fileid'), + $query->expr()->in('vco.categoryid', $this->getFavoriteVCategoryFun($query, $userId)), )); } + private function getFavoriteVCategoryFun(IQueryBuilder &$query, string $userId) { + return $query->createFunction( + $query->getConnection()->getQueryBuilder()->select('id')->from('vcategory', 'vc')->where( + $query->expr()->andX( + $query->expr()->eq('type', $query->createNamedParameter("files")), + $query->expr()->eq('uid', $query->createNamedParameter($userId)), + $query->expr()->eq('category', $query->createNamedParameter(ITags::TAG_FAVORITE)), + ))->getSQL()); + } + public function videoFilter(IQueryBuilder $query, string $userId) { $query->andWhere($query->expr()->eq('m.isvideo', $query->createNamedParameter('1'))); }