mirror of
https://github.com/Deathgarden-Rebirth/Deathgarden_Rebirth-Rewrite.git
synced 2026-09-09 19:55:22 -05:00
Simplified caching for online players api endpoint
Alsoa dded Bruno Request for online players endpoint Updated npm browser list
This commit is contained in:
@@ -2,13 +2,28 @@
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Console\Commands\CacheOnlinePlayerStats;
|
||||
use App\Enums\Game\Matchmaking\MatchmakingSide;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Responses\Api\Statistics\OnlinePlayersResponse;
|
||||
use App\Models\Game\Matchmaking\QueuedPlayer;
|
||||
use DB;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class StatisticsController extends Controller
|
||||
{
|
||||
const CACHE_KEY = 'online-players-response';
|
||||
|
||||
public function getOnlinePlayers() {
|
||||
return \Cache::get(CacheOnlinePlayerStats::CACHE_KEY);
|
||||
return Cache::remember(static::CACHE_KEY, 10, function () {
|
||||
$queuedHunters = QueuedPlayer::whereSide(MatchmakingSide::Hunter)->count();
|
||||
$queuedRunners = QueuedPlayer::whereSide(MatchmakingSide::Runner)->count();
|
||||
$inGamePlayers = DB::table('game_user')->count();
|
||||
|
||||
return json_encode(new OnlinePlayersResponse(
|
||||
$queuedRunners,
|
||||
$queuedHunters,
|
||||
$inGamePlayers,
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user