Merge pull request #3055 from pixelfed/staging

Improve DiscoverService
This commit is contained in:
daniel 2021-12-19 04:08:15 -07:00 committed by GitHub
commit ff1a12cdd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 18 deletions

View file

@ -2446,7 +2446,7 @@ class ApiV1Controller extends Controller
$pid = $request->user()->profile_id; $pid = $request->user()->profile_id;
$filters = UserFilterService::filters($pid); $filters = UserFilterService::filters($pid);
$forYou = DiscoverService::getForYou(); $forYou = DiscoverService::getForYou();
$posts = $forYou->random(50)->map(function($post) { $posts = $forYou->take(50)->map(function($post) {
return StatusService::get($post); return StatusService::get($post);
}) })
->filter(function($post) use($filters) { ->filter(function($post) use($filters) {

View file

@ -72,7 +72,7 @@ class InternalApiController extends Controller
$pid = $request->user()->profile_id; $pid = $request->user()->profile_id;
$filters = UserFilterService::filters($pid); $filters = UserFilterService::filters($pid);
$forYou = DiscoverService::getForYou(); $forYou = DiscoverService::getForYou();
$posts = $forYou->random(50)->map(function($post) { $posts = $forYou->take(50)->map(function($post) {
return StatusService::get($post); return StatusService::get($post);
}) })
->filter(function($post) use($filters) { ->filter(function($post) use($filters) {

View file

@ -3,24 +3,22 @@
namespace App\Services; namespace App\Services;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use App\Status; use Illuminate\Support\Facades\DB;
class DiscoverService class DiscoverService
{ {
public static function getDailyIdPool() public static function getDailyIdPool()
{ {
$min_id = SnowflakeService::byDate(now()->subMonths(3)); $min_id = SnowflakeService::byDate(now()->subMonths(3));
return Status::select( $sqld = config('database.default') == 'mysql';
'id', return DB::table('statuses')
'is_nsfw',
'profile_id',
'type',
'uri',
)
->whereNull('uri') ->whereNull('uri')
->whereType('photo') ->whereType('photo')
->whereIsNsfw(false) ->whereIsNsfw(false)
->whereVisibility('public') ->whereVisibility('public')
->when($sqld, function($q, $sqld) {
return $q->groupBy('profile_id');
})
->where('id', '>', $min_id) ->where('id', '>', $min_id)
->inRandomOrder() ->inRandomOrder()
->take(300) ->take(300)