X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/a04a800258b726876ff2badffe903b247aa0f676..refs/pull/2734/head:/app/Actions/ViewService.php diff --git a/app/Actions/ViewService.php b/app/Actions/ViewService.php index ec57cdb76..a4e620d4b 100644 --- a/app/Actions/ViewService.php +++ b/app/Actions/ViewService.php @@ -65,7 +65,7 @@ class ViewService { $skipCount = $count * $page; $query = $this->permissionService - ->filterRestrictedEntityRelations($this->view, 'views', 'viewable_id', 'viewable_type', $action) + ->filterRestrictedEntityRelations($this->view->newQuery(), 'views', 'viewable_id', 'viewable_type', $action) ->select('*', 'viewable_id', 'viewable_type', DB::raw('SUM(views) as view_count')) ->groupBy('viewable_id', 'viewable_type') ->orderBy('view_count', 'desc'); @@ -74,7 +74,12 @@ class ViewService $query->whereIn('viewable_type', $this->entityProvider->getMorphClasses($filterModels)); } - return $query->with('viewable')->skip($skipCount)->take($count)->get()->pluck('viewable'); + return $query->with('viewable') + ->skip($skipCount) + ->take($count) + ->get() + ->pluck('viewable') + ->filter(); } /** @@ -91,6 +96,7 @@ class ViewService /** @var Entity $instance */ foreach ($this->entityProvider->all() as $name => $instance) { $items = $instance::visible()->withLastView() + ->having('last_viewed_at', '>', 0) ->orderBy('last_viewed_at', 'desc') ->skip($count * ($page - 1)) ->take($count)