mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 14:31:26 +00:00
Add DiscoverService
This commit is contained in:
parent
2f0cd86ce3
commit
493c5ca0ce
1 changed files with 36 additions and 0 deletions
36
app/Services/DiscoverService.php
Normal file
36
app/Services/DiscoverService.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Status;
|
||||
|
||||
class DiscoverService
|
||||
{
|
||||
public static function getDailyIdPool()
|
||||
{
|
||||
$min_id = SnowflakeService::byDate(now()->subMonths(3));
|
||||
return Status::select(
|
||||
'id',
|
||||
'is_nsfw',
|
||||
'profile_id',
|
||||
'type',
|
||||
'uri',
|
||||
)
|
||||
->whereNull('uri')
|
||||
->whereType('photo')
|
||||
->whereIsNsfw(false)
|
||||
->whereVisibility('public')
|
||||
->where('id', '>', $min_id)
|
||||
->inRandomOrder()
|
||||
->take(300)
|
||||
->pluck('id');
|
||||
}
|
||||
|
||||
public static function getForYou()
|
||||
{
|
||||
return Cache::remember('pf:services:discover:for-you', 21600, function() {
|
||||
return self::getDailyIdPool();
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue