From b62e73735caeb6d52ddfc2564bf1e5ed9b74394d Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Thu, 6 Oct 2022 12:24:45 -0700 Subject: [PATCH] Allow querying multiple day ids --- lib/Controller/ApiController.php | 9 +++++++-- lib/Db/TimelineQueryDays.php | 26 +++++++++++++++++++------- src/types.ts | 2 ++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 91e9e468..345d0333 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -93,7 +93,7 @@ class ApiController extends Controller { $day["detail"] = $this->timelineQuery->getDay( $folder, $uid, - $day["dayid"], + [$day["dayid"]], $recursive, $archive, $transforms, @@ -183,6 +183,11 @@ class ApiController extends Controller { } $uid = $user->getUID(); + // Split at commas and convert all parts to int + $day_ids = array_map(function ($part) { + return intval($part); + }, explode(",", $id)); + // Get the folder to show $folder = $this->getRequestFolder(); $recursive = is_null($this->request->getParam('folder')); @@ -195,7 +200,7 @@ class ApiController extends Controller { $list = $this->timelineQuery->getDay( $folder, $uid, - intval($id), + $day_ids, $recursive, $archive, $this->getTransformations(), diff --git a/lib/Db/TimelineQueryDays.php b/lib/Db/TimelineQueryDays.php index 0232b3f3..bf698aec 100644 --- a/lib/Db/TimelineQueryDays.php +++ b/lib/Db/TimelineQueryDays.php @@ -34,6 +34,7 @@ trait TimelineQueryDays { // Convert field types $row["fileid"] = intval($row["fileid"]); $row["isvideo"] = intval($row["isvideo"]); + $row["dayid"] = intval($row["dayid"]); if (!$row["isvideo"]) { unset($row["isvideo"]); } @@ -98,7 +99,12 @@ trait TimelineQueryDays { /** * Get the days response from the database for the timeline - * @param string $userId + * + * @param Folder $folder The folder to get the days from + * @param bool $recursive Whether to get the days recursively + * @param bool $archive Whether to get the days only from the archive folder + * @param array $queryTransforms An array of query transforms to apply to the query + * @return array The days response */ public function getDays( Folder &$folder, @@ -130,14 +136,20 @@ trait TimelineQueryDays { return $this->processDays($rows); } - /** - * Get the days response from the database for the timeline - * @param string $userId + /** + * Get the day response from the database for the timeline + * @param Folder $folder The folder to get the day from + * @param string $uid The user id + * @param int[] $dayid The day id + * @param bool $recursive If the query should be recursive + * @param bool $archive If the query should include only the archive folder + * @param array $queryTransforms The query transformations to apply + * @return array An array of day responses */ public function getDay( Folder &$folder, string $uid, - int $dayid, + array $day_ids, bool $recursive, bool $archive, array $queryTransforms = [] @@ -150,10 +162,10 @@ trait TimelineQueryDays { // We don't actually use m.datetaken here, but postgres // needs that all fields in ORDER BY are also in SELECT // when using DISTINCT on selected fields - $query->select($fileid, 'f.etag', 'm.isvideo', 'vco.categoryid', 'm.datetaken') + $query->select($fileid, 'f.etag', 'm.isvideo', 'vco.categoryid', 'm.datetaken', 'm.dayid') ->from('memories', 'm') ->innerJoin('m', 'filecache', 'f', $this->getFilecacheJoinQuery($query, $folder, $recursive, $archive)) - ->andWhere($query->expr()->eq('m.dayid', $query->createNamedParameter($dayid, IQueryBuilder::PARAM_INT))); + ->andWhere($query->expr()->in('m.dayid', $query->createNamedParameter($day_ids, IQueryBuilder::PARAM_INT_ARRAY))); // Add favorite field $this->addFavoriteTag($query, $uid); diff --git a/src/types.ts b/src/types.ts index 3809725e..380eb9e9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -37,6 +37,8 @@ export type IPhoto = { etag?: string; /** Bit flags */ flag: number; + /** DayID from server */ + dayid?: number; /** Reference to day object */ d?: IDay; /** Video flag from server */