diff --git a/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php b/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php index 245172cf2d..d57d9199db 100644 --- a/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php +++ b/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php @@ -1396,10 +1396,12 @@ public function getRealEditionCapabilities() * * @param bool $editing_context If we are in a editing context or no. Default false * @param int $ttl Cache TTL in seconds. Default 60. Use -1 to deactivate the cache. + * @param bool $get_expression If we need the expression and not the SQL + * @param bool $use_cache If we need to not use cache * * @return array associative array containing the keys 'expression' and 'polygon' */ - protected function requestPolygonFilter($editing_context = false, $ttl = 60) + protected function requestPolygonFilter($editing_context = false, $ttl = 60, $get_expression = false, $use_cache = true) { // No filter response $no_filter_array = array( @@ -1449,17 +1451,12 @@ protected function requestPolygonFilter($editing_context = false, $ttl = 60) } // Get cached filter for this repository, project, layer, login and editing context - // TODO: Use the project cache tools - $use_cache = false; - // $use_cache = ($ttl > 0); - // $key = $this->project->getKey().'_'.$repository->getKey(); - // $key .= '_'.$this->id.'_'.$user_key; - // $key .= '_'.(string) $editing_context; - // $cache_key = md5($key); - // $cached_filter = jCache::get($cache_key); - // if ($cached_filter && $use_cache) { - // return json_decode($cached_filter); - // } + $cache_key = session_id().'-lizmap-polygon-filter'; + $cache_key .= '-'.$this->name; // layer + $cache_key .= '-'.$user_key; // login + if ($editing_context) { + $cache_key .= '-editing'; + } // Request the "polygon filter" string from QGIS Server lizmap plugin $params = array( @@ -1468,6 +1465,28 @@ protected function requestPolygonFilter($editing_context = false, $ttl = 60) 'map' => $this->project->getRelativeQgisPath(), 'layer' => $this->name, ); + if ($get_expression) { + $params['filter_type'] = 'expression'; + $cache_key .= '-expression'; + } + $cache_key = 'getsubsetstring-'.sha1($cache_key); + $cached = false; + + if ($use_cache) { + try { + $cached = $this->project->getCacheHandler()->getProjectRelatedDataCache($cache_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'); + $use_cache = false; + } + } + + // return cached data + if ($cached !== false) { + return $cached; + } // Add user and groups in parameters $user_and_groups = array( @@ -1507,8 +1526,7 @@ protected function requestPolygonFilter($editing_context = false, $ttl = 60) ); if ($use_cache) { - // Todo: use the project cache tools - // jCache::set($cache_key, json_encode($polygon_filter_data), $ttl); + $cached = $this->project->getCacheHandler()->setProjectRelatedDataCache($cache_key, $polygon_filter_data, 3600); } return $polygon_filter_data; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 98df157f6a..7d3c9222b5 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -335,11 +335,6 @@ parameters: count: 3 path: lizmap/modules/lizmap/classes/qgisVectorLayer.class.php - - - message: "#^If condition is always false\\.$#" - count: 1 - path: lizmap/modules/lizmap/classes/qgisVectorLayer.class.php - - message: "#^Method qgisVectorLayer\\:\\:getConstraints\\(\\) should return array\\ but returns array\\\\.$#" count: 1