a70ed81908
Removes page/chpater addSelect global query, to load book slug, and instead extracts base queries to be managed in new static class, while updating specific entitiy relation loading to use our more efficient MixedEntityListLoader where appropriate. Related to #4823
35 lines
878 B
PHP
35 lines
878 B
PHP
<?php
|
|
|
|
namespace BookStack\Entities\Queries;
|
|
|
|
use BookStack\Activity\Models\View;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class RecentlyViewed extends EntityQuery
|
|
{
|
|
public function run(int $count, int $page): Collection
|
|
{
|
|
$user = user();
|
|
if ($user->isGuest()) {
|
|
return collect();
|
|
}
|
|
|
|
$query = $this->permissionService()->restrictEntityRelationQuery(
|
|
View::query(),
|
|
'views',
|
|
'viewable_id',
|
|
'viewable_type'
|
|
)
|
|
->orderBy('views.updated_at', 'desc')
|
|
->where('user_id', '=', user()->id);
|
|
|
|
$views = $query
|
|
->skip(($page - 1) * $count)
|
|
->take($count)
|
|
->get();
|
|
|
|
$this->mixedEntityListLoader()->loadIntoRelations($views->all(), 'viewable', false);
|
|
|
|
return $views->pluck('viewable')->filter();
|
|
}
|
|
}
|