Merge pull request #3632 from pixelfed/staging

Staging
This commit is contained in:
daniel 2022-08-23 22:54:11 -06:00 committed by GitHub
commit 99fe46ead4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 28 deletions

View File

@ -3028,21 +3028,23 @@ class ApiV1Controller extends Controller
abort_if(!$request->user(), 403); abort_if(!$request->user(), 403);
$pid = $request->user()->profile_id; $pid = $request->user()->profile_id;
$ids = DB::table('profiles') $ids = Cache::remember('api:v1.1:discover:accounts:popular', 86400, function() {
return DB::table('profiles')
->where('is_private', false) ->where('is_private', false)
->whereNull('status') ->whereNull('status')
->orderByDesc('profiles.followers_count') ->orderByDesc('profiles.followers_count')
->limit(20) ->limit(20)
->get(); ->get();
});
$ids = $ids->map(function($profile) { $ids = $ids->map(function($profile) {
return AccountService::getMastodon($profile->id); return AccountService::getMastodon($profile->id, true);
}) })
->filter(function($profile) use($pid) { ->filter(function($profile) use($pid) {
return $profile && return $profile && isset($profile['id']);
isset($profile['id']) && })
!FollowerService::follows($pid, $profile['id']) && ->filter(function($profile) use($pid) {
$profile['id'] != $pid; return $profile['id'] != $pid;
}) })
->take(6) ->take(6)
->values(); ->values();

View File

@ -311,7 +311,7 @@ class ComposeController extends Controller
public function searchLocation(Request $request) public function searchLocation(Request $request)
{ {
abort_if(!Auth::check(), 403); abort_if(!$request->user(), 403);
$this->validate($request, [ $this->validate($request, [
'q' => 'required|string|max:100' 'q' => 'required|string|max:100'
]); ]);

View File

@ -123,7 +123,7 @@ class DiscoverController extends Controller
public function trendingApi(Request $request) public function trendingApi(Request $request)
{ {
abort_if(config('instance.discover.public') == false && !Auth::check(), 403); abort_if(config('instance.discover.public') == false && !$request->user(), 403);
$this->validate($request, [ $this->validate($request, [
'range' => 'nullable|string|in:daily,monthly,yearly', 'range' => 'nullable|string|in:daily,monthly,yearly',
@ -179,7 +179,10 @@ class DiscoverController extends Controller
public function trendingHashtags(Request $request) public function trendingHashtags(Request $request)
{ {
$res = StatusHashtag::select('hashtag_id', \DB::raw('count(*) as total')) abort_if(!$request->user(), 403);
$res = Cache::remember('api:discover:v1.1:trending:hashtags', 3600, function() {
return StatusHashtag::select('hashtag_id', \DB::raw('count(*) as total'))
->groupBy('hashtag_id') ->groupBy('hashtag_id')
->orderBy('total','desc') ->orderBy('total','desc')
->where('created_at', '>', now()->subDays(90)) ->where('created_at', '>', now()->subDays(90))
@ -191,9 +194,10 @@ class DiscoverController extends Controller
'id' => $hashtag->id, 'id' => $hashtag->id,
'total' => $h->total, 'total' => $h->total,
'name' => '#'.$hashtag->name, 'name' => '#'.$hashtag->name,
'url' => $hashtag->url('?src=dsh1') 'url' => $hashtag->url()
]; ];
}); });
});
return $res; return $res;
} }

View File

@ -105,6 +105,16 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
Route::group(['prefix' => 'stories'], function () use($middleware) { Route::group(['prefix' => 'stories'], function () use($middleware) {
Route::get('recent', 'StoryController@recent')->middleware($middleware); Route::get('recent', 'StoryController@recent')->middleware($middleware);
}); });
Route::group(['prefix' => 'compose/v0'], function () use($middleware) {
Route::get('/search/location', 'ComposeController@searchLocation')->middleware($middleware);
});
Route::group(['prefix' => 'discover'], function () use($middleware) {
Route::get('accounts/popular', 'Api\ApiV1Controller@discoverAccountsPopular')->middleware($middleware);
Route::get('posts/trending', 'DiscoverController@trendingApi')->middleware($middleware);
Route::get('posts/hashtags', 'DiscoverController@trendingHashtags')->middleware($middleware);
});
}); });
Route::group(['prefix' => 'live'], function() use($middleware) { Route::group(['prefix' => 'live'], function() use($middleware) {