DiscoverService.php 747 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Services;
  3. use Illuminate\Support\Facades\Cache;
  4. use Illuminate\Support\Facades\DB;
  5. class DiscoverService
  6. {
  7. public static function getDailyIdPool()
  8. {
  9. $min_id = SnowflakeService::byDate(now()->subMonths(3));
  10. $sqld = config('database.default') == 'mysql';
  11. return DB::table('statuses')
  12. ->whereNull('uri')
  13. ->whereType('photo')
  14. ->whereIsNsfw(false)
  15. ->whereVisibility('public')
  16. ->when($sqld, function($q, $sqld) {
  17. return $q->groupBy('profile_id');
  18. })
  19. ->where('id', '>', $min_id)
  20. ->inRandomOrder()
  21. ->take(300)
  22. ->pluck('id');
  23. }
  24. public static function getForYou()
  25. {
  26. return Cache::remember('pf:services:discover:for-you', 21600, function() {
  27. return self::getDailyIdPool();
  28. });
  29. }
  30. }