diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 276b1fb2..0d389ece 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -3028,24 +3028,26 @@ class ApiV1Controller extends Controller abort_if(!$request->user(), 403); $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) ->whereNull('status') ->orderByDesc('profiles.followers_count') ->limit(20) ->get(); + }); $ids = $ids->map(function($profile) { - return AccountService::getMastodon($profile->id); - }) - ->filter(function($profile) use($pid) { - return $profile && - isset($profile['id']) && - !FollowerService::follows($pid, $profile['id']) && - $profile['id'] != $pid; - }) - ->take(6) - ->values(); + return AccountService::getMastodon($profile->id, true); + }) + ->filter(function($profile) use($pid) { + return $profile && isset($profile['id']); + }) + ->filter(function($profile) use($pid) { + return $profile['id'] != $pid; + }) + ->take(6) + ->values(); return $this->json($ids); } diff --git a/app/Http/Controllers/ComposeController.php b/app/Http/Controllers/ComposeController.php index 4ce4ed03..7bb43e32 100644 --- a/app/Http/Controllers/ComposeController.php +++ b/app/Http/Controllers/ComposeController.php @@ -311,7 +311,7 @@ class ComposeController extends Controller public function searchLocation(Request $request) { - abort_if(!Auth::check(), 403); + abort_if(!$request->user(), 403); $this->validate($request, [ 'q' => 'required|string|max:100' ]); diff --git a/app/Http/Controllers/DiscoverController.php b/app/Http/Controllers/DiscoverController.php index a231f86d..4fa370be 100644 --- a/app/Http/Controllers/DiscoverController.php +++ b/app/Http/Controllers/DiscoverController.php @@ -123,7 +123,7 @@ class DiscoverController extends Controller 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, [ 'range' => 'nullable|string|in:daily,monthly,yearly', @@ -179,21 +179,25 @@ class DiscoverController extends Controller public function trendingHashtags(Request $request) { - $res = StatusHashtag::select('hashtag_id', \DB::raw('count(*) as total')) - ->groupBy('hashtag_id') - ->orderBy('total','desc') - ->where('created_at', '>', now()->subDays(90)) - ->take(9) - ->get() - ->map(function($h) { - $hashtag = $h->hashtag; - return [ - 'id' => $hashtag->id, - 'total' => $h->total, - 'name' => '#'.$hashtag->name, - 'url' => $hashtag->url('?src=dsh1') - ]; - }); + 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') + ->orderBy('total','desc') + ->where('created_at', '>', now()->subDays(90)) + ->take(9) + ->get() + ->map(function($h) { + $hashtag = $h->hashtag; + return [ + 'id' => $hashtag->id, + 'total' => $h->total, + 'name' => '#'.$hashtag->name, + 'url' => $hashtag->url() + ]; + }); + }); return $res; } diff --git a/routes/api.php b/routes/api.php index f3d0db24..20c98c17 100644 --- a/routes/api.php +++ b/routes/api.php @@ -105,6 +105,16 @@ Route::group(['prefix' => 'api'], function() use($middleware) { Route::group(['prefix' => 'stories'], function () use($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) {