From 614900443d097730446bb87f4869d64b43918bb2 Mon Sep 17 00:00:00 2001 From: yuri Date: Tue, 13 Nov 2018 17:14:22 +0200 Subject: [PATCH] fix last viewed 2 --- application/Espo/Services/LastViewed.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/application/Espo/Services/LastViewed.php b/application/Espo/Services/LastViewed.php index 8087f78a99..139d15cba4 100644 --- a/application/Espo/Services/LastViewed.php +++ b/application/Espo/Services/LastViewed.php @@ -66,15 +66,20 @@ class LastViewed extends \Espo\Core\Services\Base 'groupBy' => ['targetId', 'targetType'] ]; - $collection = $repository->limit($offset, $maxSize)->find($selectParams); - - $total = $repository->count($selectParams); + $collection = $repository->limit($offset, $params['maxSize'] + 1)->find($selectParams); foreach ($collection as $i => $entity) { $actionHistoryRecordService->loadParentNameFields($entity); $entity->set('id', \Espo\Core\Utils\Util::generateId()); } + if ($maxSize && count($collection) > $maxSize) { + $total = -1; + unset($collection[count($collection) - 1]); + } else { + $total = -2; + } + return (object) [ 'total' => $total, 'collection' => $collection