Skip to content

Commit

Permalink
Small performance improvement when checking for an empty query result…
Browse files Browse the repository at this point in the history
…. We don't need to check all layers, just find the first with results.
  • Loading branch information
sdlime committed Feb 29, 2024
1 parent d1d1375 commit c31fbb5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/mapservutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -1992,13 +1992,15 @@ int msCGIDispatchQueryRequest(mapservObj *mapserv) {
/* catch empty result set when web->empty is set (#6907) */
if (mapserv->map->web.empty != NULL ||
CPLGetConfigOption("MS_EMPTY_URL", NULL) != NULL) {
int n = 0;
int empty = MS_TRUE;
for (int i = 0; i < mapserv->map->numlayers; i++) { // count results
if (mapserv->map->layers[i]->resultcache) {
n += mapserv->map->layers[i]->resultcache->numresults;
if (mapserv->map->layers[i]->resultcache &&
mapserv->map->layers[i]->resultcache->numresults > 0) {
empty = MS_FALSE;
break;
}
}
if (n == 0) {
if (empty == MS_TRUE) {
/* note: this error message will not be displayed */
msSetError(MS_NOTFOUND, "No matching record(s) found.",
"msCGIDispatchQueryRequest()");
Expand Down

0 comments on commit c31fbb5

Please sign in to comment.