1
0
Fork 0

Merge pull request #2849 from pixelfed/staging

Update PublicApiController, fix public timeline filtering
This commit is contained in:
daniel 2021-07-08 17:35:05 -06:00 committed by GitHub
commit 52b1a1ca39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 18 deletions

View File

@ -296,25 +296,60 @@ class PublicApiController extends Controller
->whereIn('filter_type', ['mute', 'block']) ->whereIn('filter_type', ['mute', 'block'])
->pluck('filterable_id')->toArray(); ->pluck('filterable_id')->toArray();
if(PublicTimelineService::count() == 0) { if($min || $max) {
PublicTimelineService::warmCache(true, 400); $dir = $min ? '>' : '<';
} $id = $min ?? $max;
$timeline = Status::select(
if ($max) { 'id',
$feed = PublicTimelineService::getRankedMaxId($max, $limit); 'profile_id',
} else if ($min) { 'type',
$feed = PublicTimelineService::getRankedMinId($min, $limit); 'scope',
} else { 'local'
$feed = PublicTimelineService::get(0, $limit); )->where('id', $dir, $id)
} ->whereIn('type', ['text', 'photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->whereNotIn('profile_id', $filtered)
$res = collect($feed) ->whereLocal(true)
->map(function($k) use($user) { ->whereScope('public')
$status = StatusService::get($k); ->orderBy('id', 'desc')
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k); ->limit($limit)
->get()
->map(function($s) use ($user) {
$status = StatusService::get($s->id);
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
return $status; return $status;
}) });
->toArray(); $res = $timeline->toArray();
} else {
$timeline = Status::select(
'id',
'uri',
'caption',
'rendered',
'profile_id',
'type',
'in_reply_to_id',
'reblog_of_id',
'is_nsfw',
'scope',
'local',
'reply_count',
'comments_disabled',
'created_at',
'place_id',
'likes_count',
'reblogs_count',
'updated_at'
)->whereIn('type', ['text', 'photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
->whereNotIn('profile_id', $filtered)
->with('profile', 'hashtags', 'mentions')
->whereLocal(true)
->whereScope('public')
->orderBy('id', 'desc')
->simplePaginate($limit);
$fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
$res = $this->fractal->createData($fractal)->toArray();
}
return response()->json($res); return response()->json($res);
} }

View File

@ -48,6 +48,8 @@ class PublicTimelineService {
public static function add($val) public static function add($val)
{ {
return;
if(config('database.redis.client') === 'phpredis' && self::count() > 400) { if(config('database.redis.client') === 'phpredis' && self::count() > 400) {
Redis::zpopmin(self::CACHE_KEY); Redis::zpopmin(self::CACHE_KEY);
} }
@ -73,6 +75,7 @@ class PublicTimelineService {
public static function warmCache($force = false, $limit = 100) public static function warmCache($force = false, $limit = 100)
{ {
if(self::count() == 0 || $force == true) { if(self::count() == 0 || $force == true) {
Redis::del(self::CACHE_KEY);
$ids = Status::whereNull('uri') $ids = Status::whereNull('uri')
->whereNull('in_reply_to_id') ->whereNull('in_reply_to_id')
->whereNull('reblog_of_id') ->whereNull('reblog_of_id')