mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-03 11:43:17 +00:00
Merge pull request #2556 from pixelfed/staging
Update Controllers, add last_active_at logic
This commit is contained in:
commit
38a01032a2
3 changed files with 49 additions and 9 deletions
|
@ -1320,6 +1320,15 @@ class ApiV1Controller extends Controller
|
||||||
$min = $request->input('min_id');
|
$min = $request->input('min_id');
|
||||||
$max = $request->input('max_id');
|
$max = $request->input('max_id');
|
||||||
$limit = $request->input('limit') ?? 3;
|
$limit = $request->input('limit') ?? 3;
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
$key = 'user:last_active_at:id:'.$user->id;
|
||||||
|
$ttl = now()->addMinutes(5);
|
||||||
|
Cache::remember($key, $ttl, function() use($user) {
|
||||||
|
$user->last_active_at = now();
|
||||||
|
$user->save();
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
$pid = $request->user()->profile_id;
|
$pid = $request->user()->profile_id;
|
||||||
|
|
||||||
|
@ -1424,6 +1433,15 @@ class ApiV1Controller extends Controller
|
||||||
$min = $request->input('min_id');
|
$min = $request->input('min_id');
|
||||||
$max = $request->input('max_id');
|
$max = $request->input('max_id');
|
||||||
$limit = $request->input('limit') ?? 3;
|
$limit = $request->input('limit') ?? 3;
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
$key = 'user:last_active_at:id:'.$user->id;
|
||||||
|
$ttl = now()->addMinutes(5);
|
||||||
|
Cache::remember($key, $ttl, function() use($user) {
|
||||||
|
$user->last_active_at = now();
|
||||||
|
$user->save();
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
if($min || $max) {
|
if($min || $max) {
|
||||||
$dir = $min ? '>' : '<';
|
$dir = $min ? '>' : '<';
|
||||||
|
@ -1452,6 +1470,7 @@ class ApiV1Controller extends Controller
|
||||||
->with('profile', 'hashtags', 'mentions')
|
->with('profile', 'hashtags', 'mentions')
|
||||||
->where('id', $dir, $id)
|
->where('id', $dir, $id)
|
||||||
->whereScope('public')
|
->whereScope('public')
|
||||||
|
->where('created_at', '>', now()->subDays(14))
|
||||||
->latest()
|
->latest()
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->get();
|
->get();
|
||||||
|
@ -1479,6 +1498,7 @@ class ApiV1Controller extends Controller
|
||||||
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
|
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
|
||||||
->with('profile', 'hashtags', 'mentions')
|
->with('profile', 'hashtags', 'mentions')
|
||||||
->whereScope('public')
|
->whereScope('public')
|
||||||
|
->where('created_at', '>', now()->subDays(14))
|
||||||
->latest()
|
->latest()
|
||||||
->simplePaginate($limit);
|
->simplePaginate($limit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,26 +170,26 @@ class DiscoverController extends Controller
|
||||||
public function trendingApi(Request $request)
|
public function trendingApi(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($request, [
|
$this->validate($request, [
|
||||||
'range' => 'nullable|string|in:daily,monthly,alltime'
|
'range' => 'nullable|string|in:daily,monthly'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$range = $request->filled('range') ?
|
$range = $request->filled('range') ?
|
||||||
$request->input('range') == 'alltime' ? '-1' :
|
$request->input('range') == 'alltime' ? '-1' :
|
||||||
($request->input('range') == 'daily' ? 1 : 31) : 1;
|
($request->input('range') == 'daily' ? 1 : 31) : 1;
|
||||||
|
|
||||||
$key = ':api:discover:trending:v2:range:' . $range;
|
$key = ':api:discover:trending:v2.1:range:' . $range;
|
||||||
$ttl = now()->addHours(2);
|
$ttl = now()->addHours(2);
|
||||||
$res = Cache::remember($key, $ttl, function() use($range) {
|
$res = Cache::remember($key, $ttl, function() use($range) {
|
||||||
if($range == '-1') {
|
if($range == '-1') {
|
||||||
$res = Status::whereScope('public')
|
$res = Status::whereScope('public')
|
||||||
->whereType('photo')
|
->whereIn('type', ['photo', 'photo:album', 'video'])
|
||||||
->whereIsNsfw(false)
|
->whereIsNsfw(false)
|
||||||
->orderBy('likes_count','desc')
|
->orderBy('likes_count','desc')
|
||||||
->take(12)
|
->take(12)
|
||||||
->get();
|
->get();
|
||||||
} else {
|
} else {
|
||||||
$res = Status::whereScope('public')
|
$res = Status::whereScope('public')
|
||||||
->whereType('photo')
|
->whereIn('type', ['photo', 'photo:album', 'video'])
|
||||||
->whereIsNsfw(false)
|
->whereIsNsfw(false)
|
||||||
->orderBy('likes_count','desc')
|
->orderBy('likes_count','desc')
|
||||||
->take(12)
|
->take(12)
|
||||||
|
|
|
@ -272,8 +272,17 @@ class PublicApiController extends Controller
|
||||||
$min = $request->input('min_id');
|
$min = $request->input('min_id');
|
||||||
$max = $request->input('max_id');
|
$max = $request->input('max_id');
|
||||||
$limit = $request->input('limit') ?? 3;
|
$limit = $request->input('limit') ?? 3;
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
$filtered = UserFilter::whereUserId(Auth::user()->profile_id)
|
$key = 'user:last_active_at:id:'.$user->id;
|
||||||
|
$ttl = now()->addMinutes(5);
|
||||||
|
Cache::remember($key, $ttl, function() use($user) {
|
||||||
|
$user->last_active_at = now();
|
||||||
|
$user->save();
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
|
$filtered = UserFilter::whereUserId($user->profile_id)
|
||||||
->whereFilterableType('App\Profile')
|
->whereFilterableType('App\Profile')
|
||||||
->whereIn('filter_type', ['mute', 'block'])
|
->whereIn('filter_type', ['mute', 'block'])
|
||||||
->pluck('filterable_id')->toArray();
|
->pluck('filterable_id')->toArray();
|
||||||
|
@ -301,10 +310,11 @@ class PublicApiController extends Controller
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at'
|
'updated_at'
|
||||||
)->where('id', $dir, $id)
|
)->where('id', $dir, $id)
|
||||||
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
->whereIn('type', ['text', 'photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||||
->whereNotIn('profile_id', $filtered)
|
->whereNotIn('profile_id', $filtered)
|
||||||
->whereLocal(true)
|
->whereLocal(true)
|
||||||
->whereScope('public')
|
->whereScope('public')
|
||||||
|
->where('created_at', '>', now()->subMonths(3))
|
||||||
->orderBy('created_at', 'desc')
|
->orderBy('created_at', 'desc')
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->get();
|
->get();
|
||||||
|
@ -328,11 +338,12 @@ class PublicApiController extends Controller
|
||||||
'likes_count',
|
'likes_count',
|
||||||
'reblogs_count',
|
'reblogs_count',
|
||||||
'updated_at'
|
'updated_at'
|
||||||
)->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
)->whereIn('type', ['text', 'photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||||
->whereNotIn('profile_id', $filtered)
|
->whereNotIn('profile_id', $filtered)
|
||||||
->with('profile', 'hashtags', 'mentions')
|
->with('profile', 'hashtags', 'mentions')
|
||||||
->whereLocal(true)
|
->whereLocal(true)
|
||||||
->whereScope('public')
|
->whereScope('public')
|
||||||
|
->where('created_at', '>', now()->subMonths(3))
|
||||||
->orderBy('created_at', 'desc')
|
->orderBy('created_at', 'desc')
|
||||||
->simplePaginate($limit);
|
->simplePaginate($limit);
|
||||||
}
|
}
|
||||||
|
@ -360,6 +371,15 @@ class PublicApiController extends Controller
|
||||||
$min = $request->input('min_id');
|
$min = $request->input('min_id');
|
||||||
$max = $request->input('max_id');
|
$max = $request->input('max_id');
|
||||||
$limit = $request->input('limit') ?? 3;
|
$limit = $request->input('limit') ?? 3;
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
$key = 'user:last_active_at:id:'.$user->id;
|
||||||
|
$ttl = now()->addMinutes(5);
|
||||||
|
Cache::remember($key, $ttl, function() use($user) {
|
||||||
|
$user->last_active_at = now();
|
||||||
|
$user->save();
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: Use redis for timelines
|
// TODO: Use redis for timelines
|
||||||
// $timeline = Timeline::build()->local();
|
// $timeline = Timeline::build()->local();
|
||||||
|
@ -409,7 +429,7 @@ class PublicApiController extends Controller
|
||||||
'reblogs_count',
|
'reblogs_count',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at'
|
'updated_at'
|
||||||
)->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
)->whereIn('type', ['text','photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||||
->with('profile', 'hashtags', 'mentions')
|
->with('profile', 'hashtags', 'mentions')
|
||||||
->where('id', $dir, $id)
|
->where('id', $dir, $id)
|
||||||
->whereIn('profile_id', $following)
|
->whereIn('profile_id', $following)
|
||||||
|
@ -438,7 +458,7 @@ class PublicApiController extends Controller
|
||||||
'reblogs_count',
|
'reblogs_count',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at'
|
'updated_at'
|
||||||
)->whereIn('type', ['photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
)->whereIn('type', ['text','photo', 'photo:album', 'video', 'video:album', 'photo:video:album'])
|
||||||
->with('profile', 'hashtags', 'mentions')
|
->with('profile', 'hashtags', 'mentions')
|
||||||
->whereIn('profile_id', $following)
|
->whereIn('profile_id', $following)
|
||||||
->whereNotIn('profile_id', $filtered)
|
->whereNotIn('profile_id', $filtered)
|
||||||
|
|
Loading…
Reference in a new issue