X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/691027a522d43c5a52085b89abe3123596bf08cc..refs/pull/2734/head:/app/Actions/ViewService.php diff --git a/app/Actions/ViewService.php b/app/Actions/ViewService.php index aa75abb72..a4e620d4b 100644 --- a/app/Actions/ViewService.php +++ b/app/Actions/ViewService.php @@ -1,8 +1,8 @@ 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)