Optimiser lp_list.php

Si tu veux accélérer la page lp_list.php tu peux ajouter un cache sous la forme d’un fichier json a ce endroit :

				
					$course_id = $courseInfo['real_id'];

$flat_list = [];
    
    // Cache file name
    $cacheFile = api_get_path(SYS_ARCHIVE_PATH).'/lp_list_' . md5($course_id . $sessionId . $categoryId) . '.json';
    
    if (file_exists($cacheFile) && (time() - filemtime($cacheFile)) < 300) {
        $flat_list = json_decode(file_get_contents($cacheFile), true);

        if (isset($_SESSION['lp_id_maj'])) {

            foreach ($flat_list as $id => $details) {
                $id = $details['lp_old_id'];
                if ($id == intval($_SESSION['lp_id_maj'])) {
                    unlink($cacheFile);
                    $flat_list = [];
                     break;
                }
            }

        }

    }

    if (empty($flat_list)) {
        $list = new LearnpathList(
            $userId,
            $courseInfo,
            $sessionId,
            null,
            false,
            $categoryId
        );
        $flat_list = $list->get_flat_list();
        if (!empty($flat_list)) {
            file_put_contents($cacheFile, json_encode($flat_list));
        }
    }
				
			

Le probleme est dans ce cas qu’un cache de cinq minutes 300 secondes peux être relativement long si des opérations de déplacement et de visibilité ont eu lieu sur la catégorie lp.

Il faut donc ajouter ce code au début du fichier lp_controler.php pour saisir les modification d’un lp et effacer le cache le cas échant.

				
					$course_id = api_get_course_int_id();

if (isset($_REQUEST['lp_id'])&&!empty($_REQUEST['lp_id'])) {
    $_SESSION['lp_id_maj'] = intval($_REQUEST['lp_id']);
}

if (!$lp_found || (!empty($_REQUEST['lp_id']) && $_SESSION['oLP']->get_id() != $_REQUEST['lp_id'])) {