Permalink
Browse files

This patch is to fix the issue "GetCapabilities request is extremely …

…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.
1 parent 5449a6a commit 55558b35cd1cb870cb235da24cf0ef9d9a7e9633 @aabhayas aabhayas committed with tomkralidis Apr 29, 2015
Showing with 36 additions and 12 deletions.
  1. +36 −12 mapwms.c
View
@@ -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 */
@@ -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
*/

0 comments on commit 55558b3

Please sign in to comment.