Fix category filter for shared folders

pull/37/head
Varun Patil 2022-09-13 11:25:24 -07:00
parent be961b3fb4
commit 9c77a8f0c8
2 changed files with 19 additions and 22 deletions

View File

@ -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(

View File

@ -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')));
}