More of pooling, mapquery.c

Tamas Szekeres szekerest at GMAIL.COM
Mon May 7 08:17:39 EDT 2007


Did you test with

PROCESSING CLOSE_CONNECTION=DEFER option with your SDE layer?

Best regards,

Tamas


2007/5/7, Hallgren Johan E <jhhal at wmdata.com>:
>
>
>
>
> Hello again,
>
>
>
> I have made a test with the following code with extremely good performance.
> I have only tested this specific call, but couldn't the concept be
> implemented in other functions as well? As I see it, it will implement the
> Connection pool between mapscript calls.
>
>
>
> My added sections start with Johan START and ends with Johan END.
>
>
>
> int msQueryByAttributes(mapObj *map, int qlayer, char *qitem, char *qstring,
> int mode)
>
> {
>
>   layerObj *lp;
>
>   int status;
>
>
>
>   /* Johan START */
>
>   int bLayerWasOpen;
>
>   /* Johan START */
>
>
>
>   int old_filtertype=-1;
>
>   char *old_filterstring=NULL, *old_filteritem=NULL;
>
>
>
>   rectObj searchrect;
>
>
>
>   shapeObj shape;
>
>
>
>   if(qlayer < 0 || qlayer >= map->numlayers) {
>
>     msSetError(MS_MISCERR, "No query layer defined.",
> "msQueryByAttributes()");
>
>     return(MS_FAILURE);
>
>   }
>
>
>
>   lp = &(map->layers[qlayer]);
>
>
>
>   /* free any previous search results, do now in case one of the following
> tests fails */
>
>   if(lp->resultcache) {
>
>     if(lp->resultcache->results) free(lp->resultcache->results);
>
>     free(lp->resultcache);
>
>     lp->resultcache = NULL;
>
>   }
>
>
>
>   if(!msIsLayerQueryable(lp)) {
>
>     msSetError(MS_QUERYERR, "Requested layer has no templates defined so is
> not queryable.", "msQueryByAttributes()");
>
>     return(MS_FAILURE);
>
>   }
>
>
>
>   if(!qstring) {
>
>     msSetError(MS_QUERYERR, "No query expression defined.",
> "msQueryByAttributes()");
>
>     return(MS_FAILURE);
>
>   }
>
>
>
>   /* save any previously defined filter */
>
>   if(lp->filter.string) {
>
>     old_filtertype = lp->filter.type;
>
>     old_filterstring = strdup(lp->filter.string);
>
>     if(lp->filteritem)
>
>       old_filteritem = strdup(lp->filteritem);
>
>   }
>
>
>
>   /* apply the passed query parameters */
>
>   if(qitem)
>
>     lp->filteritem = strdup(qitem);
>
>   else
>
>     lp->filteritem = NULL;
>
>   msLoadExpressionString(&(lp->filter), qstring);
>
>
>
>   msInitShape(&shape);
>
>
>
>   /* open this layer */
>
>       /* Johan START */
>
>       //int bLayerWasOpen;
>
>       bLayerWasOpen = msLayerIsOpen(lp);
>
>   if (!bLayerWasOpen)
>
>   {
>
>             status = msLayerOpen(lp);
>
>             if(status != MS_SUCCESS) return(MS_FAILURE);
>
>       }
>
>       //status = msLayerOpen(lp);
>
>  // if(status != MS_SUCCESS) return(MS_FAILURE);
>
>       /*Johan END*/
>
>
>
>   /* build item list (no annotation) */
>
>   status = msLayerWhichItems(lp, MS_TRUE, MS_FALSE, NULL);
>
>   if(status != MS_SUCCESS) return(MS_FAILURE);
>
>
>
>   /* identify target shapes */
>
>   searchrect = map->extent;
>
> #ifdef USE_PROJ
>
>   if(lp->project && msProjectionsDiffer(&(lp->projection),
> &(map->projection)))
>
>     msProjectRect(&(map->projection), &(lp->projection),
> &searchrect); /* project the searchrect to source coords */
>
>   else
>
>     lp->project = MS_FALSE;
>
> #endif
>
>   status = msLayerWhichShapes(lp, searchrect);
>
>   if(status == MS_DONE) { /* no overlap */
>
>     msLayerClose(lp);
>
>     msSetError(MS_NOTFOUND, "No matching record(s) found, layer and area of
> interest do not overlap.", "msQueryByAttributes()");
>
>     return(MS_FAILURE);
>
>   } else if(status != MS_SUCCESS) {
>
>     msLayerClose(lp);
>
>     return(MS_FAILURE);
>
>   }
>
>
>
>   lp->resultcache = (resultCacheObj *)malloc(sizeof(resultCacheObj)); /*
> allocate and initialize the result cache */
>
>   lp->resultcache->results = NULL;
>
>   lp->resultcache->numresults = lp->resultcache->cachesize = 0;
>
>   lp->resultcache->bounds.minx = lp->resultcache->bounds.miny =
> lp->resultcache->bounds.maxx = lp->resultcache->bounds.maxy = -1;
>
>
>
>   while((status = msLayerNextShape(lp, &shape)) == MS_SUCCESS) { /* step
> through the shapes */
>
>
>
>     shape.classindex = msShapeGetClass(lp, &shape, map->scale);
>
>     if(!(lp->template) && ((shape.classindex == -1) ||
> (lp->class[shape.classindex].status == MS_OFF))) { /* not a valid shape */
>
>       msFreeShape(&shape);
>
>       continue;
>
>     }
>
>
>
>     if(!(lp->template) && !(lp->class[shape.classindex].template)) { /* no
> valid template */
>
>       msFreeShape(&shape);
>
>       continue;
>
>     }
>
>
>
> #ifdef USE_PROJ
>
>     if(lp->project &&
> msProjectionsDiffer(&(lp->projection), &(map->projection)))
>
>       msProjectShape(&(lp->projection), &(map->projection),
> &shape);
>
>     else
>
>       lp->project = MS_FALSE;
>
> #endif
>
>
>
>     addResult(lp->resultcache, shape.classindex, shape.index,
> shape.tileindex);
>
>
>
>     if(lp->resultcache->numresults == 1)
>
>       lp->resultcache->bounds = shape.bounds;
>
>     else
>
>       msMergeRect(&(lp->resultcache->bounds),
> &shape.bounds);
>
>
>
>     msFreeShape(&shape);
>
>
>
>     if(mode == MS_SINGLE) { /* no need to look any further */
>
>       status = MS_DONE;
>
>       break;
>
>     }
>
>   }
>
>
>
>   if(status != MS_DONE) return(MS_FAILURE);
>
>
>
>   /* the FILTER set was just temporary, clean up here */
>
>   freeExpression(&(lp->filter));
>
>   if(lp->filteritem) {
>
>     free(lp->filteritem);
>
>     lp->filteritem = NULL;
>
>     lp->filteritemindex = -1;
>
>   }
>
>
>
>   /* restore any previously defined filter */
>
>   if(old_filterstring) {
>
>     lp->filter.type = old_filtertype;
>
>     lp->filter.string = strdup(old_filterstring);
>
>     free(old_filterstring);
>
>     if(old_filteritem) {
>
>       lp->filteritem = strdup(old_filteritem);
>
>       free(old_filteritem);
>
>     }
>
>   }
>
>
>
>       /*Johan START*/
>
>   if (!bLayerWasOpen)
>
>   {
>
>             msLayerClose(lp);
>
>   }
>
>       //msLayerClose(lp);
>
>       /*Johan END*/
>
>
>
>
>
>   /* was anything found?  */
>
>   if(lp->resultcache && lp->resultcache->numresults > 0)
>
>     return(MS_SUCCESS);
>
>
>
>   msSetError(MS_NOTFOUND, "No matching record(s) found.",
> "msQueryByAttributes()");
>
>   return(MS_FAILURE);
>
> }
>
>
>
>
>
> /Ugh
> ___________________________________
> Johan Hallgren
>
>
>
>
>
> WM-data a LogicaCMG company
>
>
> Pelle Bergs backe 3
>
>
> Box 1938, 791 19 Falun
>
>
>
> Tel: 023-547 46 (int: +46-2354746)
>
> Mobil: 070-588 44 28 (int: +46-705884428)
>
>
> johan.e.hallgren at wmdata.com
>
>
> http://www.wmdata.se
>
>



More information about the mapserver-dev mailing list