1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-29 11:15:09 +00:00
pixelfed/app/Services/DiscoverService.php

35 lines
747 B
PHP
Raw Normal View History

2021-12-19 07:43:09 +00:00
<?php
namespace App\Services;
use Illuminate\Support\Facades\Cache;
2021-12-19 11:07:40 +00:00
use Illuminate\Support\Facades\DB;
2021-12-19 07:43:09 +00:00
class DiscoverService
{
public static function getDailyIdPool()
{
$min_id = SnowflakeService::byDate(now()->subMonths(3));
2021-12-19 11:07:40 +00:00
$sqld = config('database.default') == 'mysql';
return DB::table('statuses')
->whereNull('uri')
->whereType('photo')
->whereIsNsfw(false)
->whereVisibility('public')
->when($sqld, function($q, $sqld) {
return $q->groupBy('profile_id');
})
->where('id', '>', $min_id)
->inRandomOrder()
->take(300)
->pluck('id');
2021-12-19 07:43:09 +00:00
}
public static function getForYou()
{
return Cache::remember('pf:services:discover:for-you', 21600, function() {
return self::getDailyIdPool();
});
}
}