Skip to content

Commit cf64661

Browse files
committed
WFS: fix WFS 2.0 numberMatched computation, by opening temporary new connection(s)
1 parent 8a8ea9c commit cf64661

File tree

2 files changed

+17
-30
lines changed

2 files changed

+17
-30
lines changed

mapcopy.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1285,8 +1285,10 @@ int msCopyMap(mapObj *dst, mapObj *src)
12851285
return MS_FAILURE;
12861286
}
12871287

1288-
for (i = 0; i < dst->numlayers; i++) {
1289-
MS_COPYSTELEM(layerorder[i]);
1288+
if( src->layerorder ) {
1289+
for (i = 0; i < dst->numlayers; i++) {
1290+
MS_COPYSTELEM(layerorder[i]);
1291+
}
12901292
}
12911293
MS_COPYSTELEM(debug);
12921294
MS_COPYSTRING(dst->datapattern, src->datapattern);

mapwfs.c

+13-28
Original file line numberDiff line numberDiff line change
@@ -3004,7 +3004,6 @@ static int msWFSComputeMatchingFeatures(mapObj *map,
30043004
int nWFSVersion)
30053005
{
30063006
int nMatchingFeatures = -1;
3007-
int j;
30083007

30093008
if( nWFSVersion >= OWS_2_0_0 )
30103009
{
@@ -3056,28 +3055,24 @@ static int msWFSComputeMatchingFeatures(mapObj *map,
30563055
if( pszComputeNumberMatched != NULL &&
30573056
strcasecmp(pszComputeNumberMatched, "true") == 0 )
30583057
{
3059-
resultCacheObj** saveResultCache = (resultCacheObj** )
3060-
msSmallMalloc( map->numlayers * sizeof(resultCacheObj*));
3061-
3062-
/* Save the result cache that contains the features that we want to */
3063-
/* emit in the response */
3064-
for(j=0; j<map->numlayers; j++) {
3065-
layerObj* lp = GET_LAYER(map, j);
3066-
saveResultCache[j] = lp->resultcache;
3067-
lp->resultcache = NULL;
3058+
int j;
3059+
mapObj* mapTmp = (mapObj*)msSmallCalloc(1, sizeof(mapObj));
3060+
initMap(mapTmp);
3061+
msCopyMap(mapTmp, map);
30683062

3069-
/* Resent layer paging */
3063+
/* Re-run the query but with no limit */
3064+
mapTmp->query.maxfeatures = -1;
3065+
mapTmp->query.startindex = -1;
3066+
mapTmp->query.only_cache_result_count = MS_TRUE;
3067+
for(j=0; j<mapTmp->numlayers; j++) {
3068+
layerObj* lp = GET_LAYER(mapTmp, j);
3069+
/* Reset layer paging */
30703070
lp->maxfeatures = -1;
30713071
lp->startindex = -1;
30723072
}
30733073

3074-
/* Re-run the query but with no limit */
3075-
map->query.maxfeatures = -1;
3076-
map->query.startindex = -1;
3077-
map->query.only_cache_result_count = MS_TRUE;
3078-
30793074
nMatchingFeatures = 0;
3080-
msWFSRetrieveFeatures(map,
3075+
msWFSRetrieveFeatures(mapTmp,
30813076
ows_request,
30823077
paramsObj,
30833078
pgmlinfo,
@@ -3093,17 +3088,7 @@ static int msWFSComputeMatchingFeatures(mapObj *map,
30933088
&nMatchingFeatures,
30943089
NULL);
30953090

3096-
/* Restore the original result cache */
3097-
for(j=0; j<map->numlayers; j++) {
3098-
layerObj* lp = GET_LAYER(map, j);
3099-
if(lp->resultcache) {
3100-
if(lp->resultcache->results) free(lp->resultcache->results);
3101-
free(lp->resultcache);
3102-
lp->resultcache = NULL;
3103-
}
3104-
lp->resultcache = saveResultCache[j];
3105-
}
3106-
msFree(saveResultCache);
3091+
msFreeMap(mapTmp);
31073092
}
31083093
}
31093094
}

0 commit comments

Comments
 (0)