Files
PS_ProserveReport/ProserveAPI/htdocs/proserve/session/updateobjectives.php
j.foucher 68cea1eb4d 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>
2026-05-04 16:41:52 +02:00

71 lines
2.2 KiB
PHP

<?php
// include database and object files
include_once '../config/init.php'; // contains $db
include_once '../config/error.php';
include_once '../objects/db_participates.php';
// prepare user object
$participation = new UserInGameSession($db);
// read mandatory $_POST properties : ensure sessionId and userId are passed in POST parameters
if (isset($_POST['sessionId']))
$participation->sessionId = $_POST['sessionId'];
else trigger_error( missing_parameter_error("sessionId") );
if (isset($_POST['userId']))
$participation->userId = $_POST['userId'];
else trigger_error( missing_parameter_error("userId") );
// get overall objectives for all users in session
if ($participation->userId == -1)
{
$users = $participation->getAllUsersInSession();
if (count($users) >= 1)
$participation->userId = $users[0];
//else
//{
// foreach ($users as $userId)
// {
// $participation->userId = $userId;
// $participation->load();
// $participation->results = $results;
// }
//}
}
// load from database
if ($participation->load())
{
// read other $_POST properties
$participation->results = $_POST['results'] ?? "";
// 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
}
else trigger_error("User_Results_Not_Saved");
}
else trigger_error("Couldn't find user with id " . $participation->userId . " in session with id " . $participation->sessionId . ".");
//function loadObjectivesForParticipation ()
//{
// if ($participation->load())
// {
// // read other $_POST properties
// $participation->results = $results;
//
// // register user to the game session
// if ($participation->updateObjectives())
// {
// $participation_arr = $participation->getResultArray(true, "Results_Saved_OK");
// print_r(json_encode($participation_arr)); // OK
// }
// else trigger_error("User_Results_Not_Saved");
// }
// else trigger_error("Couldn't find user with id " . $participation->userId . " in session with id " . $participation->sessionId . ".");
//}
?>