Skip to content

Commit

Permalink
This patch is to fix the issue "GetCapabilities request is extremely …
Browse files Browse the repository at this point in the history
…slow when “OWS_LAYER_GROUP” is used"

#5081.

Changed the code to create a unique set of groups and then compare them with layer names to avoid multiple passes through layer names.
  • Loading branch information
aabhayas authored and tomkralidis committed Apr 18, 2016
1 parent 5449a6a commit 55558b3
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions mapwms.c
Expand Up @@ -363,9 +363,15 @@ int msWMSApplyTime(mapObj *map, int version, char *time, char *wms_exception_for
*/
void msWMSPrepareNestedGroups(mapObj* map, int nVersion, char*** nestedGroups, int* numNestedGroups, int* isUsedInNestedGroup)
{
int i, j, k;
int i, k;
const char* groups;
char* errorMsg;
//Create array to hold unique groups
int maxgroups = 2000;
int maxgroupiter = 1;
char** uniqgroups = malloc(maxgroups * sizeof(char*));
int uniqgroupcount = 0;


for (i = 0; i < map->numlayers; i++) {
nestedGroups[i] = NULL; /* default */
Expand All @@ -388,24 +394,42 @@ void msWMSPrepareNestedGroups(mapObj* map, int nVersion, char*** nestedGroups, i
} else {
/* split into subgroups. Start at address + 1 because the first '/' would cause an extra empty group */
nestedGroups[i] = msStringSplit(groups + 1, '/', &numNestedGroups[i]);
/* */
for (j = 0; j < map->numlayers; j++) {
if (isUsedInNestedGroup[j])
continue;

for (k=0; k<numNestedGroups[i]; k++) {
if ( GET_LAYER(map, j)->name && strcasecmp(GET_LAYER(map, j)->name, nestedGroups[i][k]) == 0 ) {
isUsedInNestedGroup[j] = 1;
/* Iterate through the groups and add them to the unique groups array */
for (k=0; k<numNestedGroups[i]; k++) {
int found ,l = 0;
found = 0;
for (l=0; l<uniqgroupcount; l++) {
if ( strcasecmp(uniqgroups[l], nestedGroups[i][k]) == 0 ){
found = 1;
break;
}
}
}
if(found == 0){
uniqgroups[uniqgroupcount] = nestedGroups[i][k];
uniqgroupcount++;
// Does need only when maximum unique groups exceed 2000
if ( uniqgroupcount == (maxgroups*maxgroupiter)){
uniqgroups = realloc(uniqgroups, (uniqgroupcount + maxgroups) * sizeof(char*));
maxgroupiter++;
}
}
}
}
}
}
}
/* Iterate through layers to find out whether they are in any of the nested groups */
for (i = 0; i < map->numlayers; i++) {
for (k=0; k<uniqgroupcount; k++) {
if ( strcasecmp(GET_LAYER(map, i)->name ,uniqgroups[k]) == 0 ){
isUsedInNestedGroup[i] = 1;
break;
}
}
}
}
}
}


/*
** Validate that a given dimension is inside the extents defined
*/
Expand Down

0 comments on commit 55558b3

Please sign in to comment.