From 66f479844e2bac1eed07fe560666ab785dc13145 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Thu, 6 Oct 2022 14:44:14 -0700 Subject: [PATCH] Add limit transform --- lib/Controller/ApiController.php | 6 ++++++ lib/Db/TimelineQueryFilters.php | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 14384940..2d2a6bb2 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -87,6 +87,12 @@ class ApiController extends Controller { $transforms[] = array($this->timelineQuery, 'transformTagFilter', $tagName); } + // Limit number of responses for day query + $limit = $this->request->getParam('limit'); + if ($limit) { + $transforms[] = array($this->timelineQuery, 'transformLimitDay', intval($limit)); + } + return $transforms; } diff --git a/lib/Db/TimelineQueryFilters.php b/lib/Db/TimelineQueryFilters.php index bfdd08da..d1e644ee 100644 --- a/lib/Db/TimelineQueryFilters.php +++ b/lib/Db/TimelineQueryFilters.php @@ -44,4 +44,8 @@ trait TimelineQueryFilters { public function transformVideoFilter(IQueryBuilder &$query, string $userId) { $query->andWhere($query->expr()->eq('m.isvideo', $query->createNamedParameter('1'))); } + + public function transformLimitDay(IQueryBuilder &$query, string $userId, int $limit) { + $query->setMaxResults($limit); + } } \ No newline at end of file