From f7ba3ab74ac100da4fc0052c52918d3ae9a7d3e4 Mon Sep 17 00:00:00 2001 From: rldhont Date: Fri, 6 Oct 2023 16:03:34 +0200 Subject: [PATCH] [Fix] Utilisation du cache handler de projet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Afin d'optimiser le module cadastre, le getcapabilities cadastre doit ĂȘtre mis en cache avec le handler du projet. Funded by [Conseil DĂ©partement du Calvados](https://www.calvados.fr) --- .../classes/lizmapCadastreRequest.class.php | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/cadastre/classes/lizmapCadastreRequest.class.php b/cadastre/classes/lizmapCadastreRequest.class.php index 63917f2..34b0eac 100644 --- a/cadastre/classes/lizmapCadastreRequest.class.php +++ b/cadastre/classes/lizmapCadastreRequest.class.php @@ -20,29 +20,29 @@ public function process_getcapabilities() protected function getcapabilities() { + $appContext = $this->appContext; // Get cached session - $key = session_id() . '-' . - $this->project->getRepository()->getKey() . '-' . - $this->project->getKey() . '-' . - $this->param('service') . '-getcapabilities'; - if (jAuth::isConnected()) { - $juser = jAuth::getUserSession(); + // the cache should be unique between each user/service because the + // request content depends on rights of the user + $key = session_id() . '-' . $this->param('service'); + $version = $this->param('version'); + if ($version) { + $key .= '-' . $version; + } + if ($appContext->UserIsConnected()) { + $juser = $appContext->getUserSession(); $key .= '-' . $juser->login; } - $key = sha1($key); + $key = 'getcapabilities-' . sha1($key); $cached = false; try { - $cached = jCache::get($key, 'qgisprojects'); + $cached = $this->project->getCacheHandler()->getProjectRelatedDataCache($key); } catch (Exception $e) { // if qgisprojects profile does not exist, or if there is an // other error about the cache, let's log it jLog::logEx($e, 'error'); } - // invalid cache - if ($cached !== false && $cached['mtime'] < $this->project->getFileTime()) { - $cached = false; - } // return cached data if ($cached !== false) { return (object) array( @@ -53,38 +53,40 @@ protected function getcapabilities() ); } - $querystring = $this->constructUrl(); - // Get remote data - list($data, $mime, $code) = lizmapProxy::getRemoteData($querystring); + $response = $this->request(); // Retry if 500 error ( hackish, but QGIS Server segfault sometimes with cache issue ) if ($code == 500) { // Get remote data - list($data, $mime, $code) = lizmapProxy::getRemoteData($querystring); + $response = $this->request(); } - if ($mime != 'text/json' && $mime != 'application/json') { - $code = 400; - $mime = 'application/json'; - $data = json_encode((object) array( - 'status' => 'fail', - 'message' => 'Cadastre - Plugin non disponible', - )); + if ($response->mime != 'text/json' && $response->mime != 'application/json') { + return (object) array( + 'code' => 400, + 'mime' => 'application/json', + 'data' => json_encode((object) array( + 'status' => 'fail', + 'message' => 'Cadastre - Plugin non disponible', + )), + 'cached' => false, + ); } - $cached = array( - 'mtime' => $this->project->getFileTime(), - 'code' => $code, - 'mime' => $mime, - 'data' => $data, - ); - $cached = jCache::set($key, $cached, 3600, 'qgisprojects'); + if ($response->code == 200) { + $cachedContent = array( + 'code' => $response->code, + 'mime' => $response->mime, + 'data' => $response->data, + ); + $cached = $this->project->getCacheHandler()->setProjectRelatedDataCache($key, $cachedContent, 3600); + } return (object) array( - 'code' => $code, - 'mime' => $mime, - 'data' => $data, + 'code' => $response->code, + 'mime' => $response->mime, + 'data' => $response->data, 'cached' => $cached, ); }