mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
d0ff79ea60
- Removed old view system and started use of new query classes instead. - Finished off RelationMultiModelQuery but found it was less efficient than x-many queries due to the amount of tables being scanned. Adding now for history but will delete as not used. - Updated recently viewed to use same query system as popular items rather than running and joining x-entities queries. - Added "Most Viewed Faviourites" listing to homepages.
29 lines
937 B
PHP
29 lines
937 B
PHP
<?php namespace BookStack\Entities\Queries;
|
|
|
|
|
|
use BookStack\Actions\View;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class Popular extends EntityQuery
|
|
{
|
|
public function run(int $count, int $page, array $filterModels = null, string $action = 'view')
|
|
{
|
|
$query = $this->permissionService()
|
|
->filterRestrictedEntityRelations(View::query(), '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');
|
|
|
|
if ($filterModels) {
|
|
$query->whereIn('viewable_type', $this->entityProvider()->getMorphClasses($filterModels));
|
|
}
|
|
|
|
return $query->with('viewable')
|
|
->skip($count * ($page - 1))
|
|
->take($count)
|
|
->get()
|
|
->pluck('viewable')
|
|
->filter();
|
|
}
|
|
|
|
} |