Simplified caching for online players api endpoint

Alsoa dded Bruno Request for online players endpoint

Updated npm browser list
This commit is contained in:
Vari
2024-08-27 19:09:48 +02:00
parent 597d34e7d8
commit 0379ef9a56
4 changed files with 33 additions and 53 deletions

View File

@@ -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,
));
});
}
}