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