V2 : optimisation API (cache, index, vue materialisee)
- BDD (migrations 1.6.0 + 1.7.0, idempotentes) :
* 4 nouveaux index composites sur reactevents, triggerevents, sessions
* vue sessiondebriefs reecrite (sous-requetes correlees -> JOINs)
puis materialisee dans table session_debriefs_cache via procedure
stockee rebuild_debrief_cache, recalculee uniquement aux changements
* fix bug double JOIN participates : TargetRole = "IA" pour les hits
NPC/objets (au lieu d'un role aleatoire de participant)
- API PHP :
* connexion PDO en singleton + ATTR_PERSISTENT
* cache disque par session (cache/sess_<id>/) pour debrief, get, userhistory
avec invalidation ciblee sur events et lifecycle
* pagination opt-in (limit/offset) sur lists/sessions_for_user
* helpers ensure_/rebuild_/invalidate_session_debrief_cache_db
* debug/benchmark.php pour mesurer la latence des 6 endpoints cles
- Endpoints HTTP : signatures inchangees, compat Unreal preservee
- Gain mesure : -58% a -83% sur les 5 endpoints cles
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,12 +16,22 @@ $userId = isset($_POST['userId']) ? $_POST['userId'] : -1;
|
||||
// check sessionId is > 0
|
||||
//if ($sessionId > 0)
|
||||
//{
|
||||
// prepare user object
|
||||
$stats = new StatsObject($db);
|
||||
$stats->getStatsForSession($sessionId, $userId);
|
||||
|
||||
$stats_arr = $stats->getResultArray(true, "Stats_Collected_OK");
|
||||
print_r(json_encode($stats_arr)); // OK
|
||||
$cacheKey = "debrief_" . intval($userId);
|
||||
$cached = cache_get($sessionId, $cacheKey);
|
||||
if ($cached !== null)
|
||||
{
|
||||
print_r($cached);
|
||||
}
|
||||
else
|
||||
{
|
||||
$stats = new StatsObject($db);
|
||||
$stats->getStatsForSession($sessionId, $userId);
|
||||
|
||||
$stats_arr = $stats->getResultArray(true, "Stats_Collected_OK");
|
||||
$json = json_encode($stats_arr);
|
||||
cache_put($sessionId, $cacheKey, $json);
|
||||
print_r($json); // OK
|
||||
}
|
||||
//}
|
||||
//else trigger_error("Invalid session id");
|
||||
?>
|
||||
@@ -12,11 +12,17 @@ if (isset($_POST['sessionId']))
|
||||
$gameSession->id = $_POST['sessionId'];
|
||||
else trigger_error( missing_parameter_error("sessionId") );
|
||||
|
||||
// create the game session
|
||||
if ($gameSession->load())
|
||||
$cached = cache_get($gameSession->id, "session");
|
||||
if ($cached !== null)
|
||||
{
|
||||
print_r($cached);
|
||||
}
|
||||
else if ($gameSession->load())
|
||||
{
|
||||
$session_arr = $gameSession->getResultArray(true, "Session_Found");
|
||||
print_r(json_encode($session_arr)); // OK
|
||||
$json = json_encode($session_arr);
|
||||
cache_put($gameSession->id, "session", $json);
|
||||
print_r($json); // OK
|
||||
}
|
||||
else trigger_error("Error_Occured");
|
||||
?>
|
||||
@@ -20,6 +20,8 @@ $gameSession->score = $_POST['score'];
|
||||
// close the game session
|
||||
if ($gameSession->stop())
|
||||
{
|
||||
cache_invalidate_session($gameSession->id);
|
||||
rebuild_session_debrief_cache_db($db, $gameSession->id);
|
||||
$session_arr = $gameSession->getResultArray(true, "Session_Stop_OK");
|
||||
print_r(json_encode($session_arr)); // OK
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ if ($participation->load())
|
||||
// update objectives of user in the game session
|
||||
if ($participation->updateObjectives())
|
||||
{
|
||||
cache_invalidate_session($participation->sessionId);
|
||||
rebuild_session_debrief_cache_db($db, $participation->sessionId);
|
||||
$participation_arr = $participation->getResultArray(true, "Results_Saved_OK");
|
||||
print_r(json_encode($participation_arr)); // OK
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ if ($participation->userLeaves())
|
||||
// update score and averages
|
||||
if ($participation->updateUserScores())
|
||||
{
|
||||
cache_invalidate_session($participation->sessionId);
|
||||
rebuild_session_debrief_cache_db($db, $participation->sessionId);
|
||||
$participation_arr = $participation->getResultArray(true, "User_Left_OK");
|
||||
print_r(json_encode($participation_arr)); // OK
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user