[mapserver-commits] r9061 - sandbox/single-pass/mapserver

svn at osgeo.org svn at osgeo.org
Tue Jun 2 00:17:18 EDT 2009


Author: sdlime
Date: 2009-06-02 00:17:18 -0400 (Tue, 02 Jun 2009)
New Revision: 9061

Modified:
   sandbox/single-pass/mapserver/mapquery.c
   sandbox/single-pass/mapserver/mapserver.h
   sandbox/single-pass/mapserver/maptemplate.c
Log:
Implemented simple shape caching for bbox queries only.

Modified: sandbox/single-pass/mapserver/mapquery.c
===================================================================
--- sandbox/single-pass/mapserver/mapquery.c	2009-06-02 03:12:48 UTC (rev 9060)
+++ sandbox/single-pass/mapserver/mapquery.c	2009-06-02 04:17:18 UTC (rev 9061)
@@ -34,12 +34,23 @@
 
 static void freeResults(layerObj *layer) 
 {
-  if(layer->resultcache->results) free(layer->resultcache->results);
+  int i;
+
+  if(layer->resultcache->results) {
+    for(i=0; i<layer->resultcache->numresults; i++) {
+      if(layer->resultcache->results[i].shape) {
+        msFreeShape(layer->resultcache->results[i].shape);
+        free(layer->resultcache->results[i].shape);
+      } else 
+        break; /* results are sequential, no shapes beyond this point are cached */
+    }
+    free(layer->resultcache->results);
+  }
   free(layer->resultcache);
   layer->resultcache = NULL;
 }
 
-int initResults(layerObj *layer) 
+static int initResults(layerObj *layer) 
 {
   layer->resultcache = (resultCacheObj *) malloc(sizeof(resultCacheObj));
   if(!(layer->resultcache)) {
@@ -54,30 +65,10 @@
   return MS_SUCCESS;
 }
 
-/*
-** msIsLayerQueryable()  returns MS_TRUE/MS_FALSE
-*/
-int msIsLayerQueryable(layerObj *lp)
+static int addResult(resultCacheObj *cache, shapeObj *shape, int cache_shape)
 {
   int i;
 
-  if ( lp->type == MS_LAYER_TILEINDEX )
-    return MS_FALSE;
-
-  if(lp->template && strlen(lp->template) > 0) return MS_TRUE;
-
-  for(i=0; i<lp->numclasses; i++) {
-    if(lp->class[i]->template && strlen(lp->class[i]->template) > 0)
-        return MS_TRUE;
-  }
-
-  return MS_FALSE;
-}
-
-static int addResult(resultCacheObj *cache, shapeObj *shape)
-{
-  int i;
-
   if(!cache || !shape) {
     msSetError(MS_MISCERR, "Unallocated cache or shape objects.", "addResult()");
     return(MS_FAILURE);
@@ -97,6 +88,16 @@
 
   i = cache->numresults;
 
+  if(cache_shape) {
+    // printf("%d adding shape: %d (%s)\n", i, shape->numlines, shape->values[5]);
+    cache->results[i].shape = (shapeObj *) malloc(sizeof(shapeObj));
+    msInitShape(cache->results[i].shape);
+    msCopyShape(shape, cache->results[i].shape);
+  } else {
+    // printf("%d adding indexes only (%s)\n", i, shape->values[5]);
+    cache->results[i].shape = NULL;
+  }
+
   cache->results[i].classindex = shape->classindex;
   cache->results[i].tileindex = shape->tileindex;
   cache->results[i].shapeindex = shape->index;
@@ -110,6 +111,26 @@
   return(MS_SUCCESS);
 }
 
+/*
+** msIsLayerQueryable()  returns MS_TRUE/MS_FALSE
+*/
+int msIsLayerQueryable(layerObj *lp)
+{
+  int i;
+
+  if ( lp->type == MS_LAYER_TILEINDEX )
+    return MS_FALSE;
+
+  if(lp->template && strlen(lp->template) > 0) return MS_TRUE;
+
+  for(i=0; i<lp->numclasses; i++) {
+    if(lp->class[i]->template && strlen(lp->class[i]->template) > 0)
+        return MS_TRUE;
+  }
+
+  return MS_FALSE;
+}
+
 int msSaveQuery(mapObj *map, char *filename) {
   FILE *stream;
   int i, j, n=0;
@@ -246,7 +267,7 @@
     return(MS_FAILURE);
   }
 
-  addResult(lp->resultcache, &shape);
+  addResult(lp->resultcache, &shape, 0);
   if(lp->resultcache->numresults == 1)
     lp->resultcache->bounds = shape.bounds;
   else
@@ -387,7 +408,7 @@
       lp->project = MS_FALSE;
 #endif
 
-    addResult(lp->resultcache, &shape);
+    addResult(lp->resultcache, &shape, 0);
     msFreeShape(&shape);
 
     if(mode == MS_SINGLE) { /* no need to look any further */
@@ -444,6 +465,8 @@
   int nclasses = 0;
   int *classgroup = NULL;
 
+  int query_cache_size; /* number of shapes to cache for a layer */
+
   msInitShape(&shape);
   msInitShape(&searchshape);
 
@@ -457,6 +480,14 @@
   for(l=start; l>=stop; l--) {
     lp = (GET_LAYER(map, l));
 
+    query_cache_size = 0;
+    if(msLayerGetProcessingKey(lp, "QUERY_CACHE_SIZE")) {
+      if(sscanf(msLayerGetProcessingKey(lp, "QUERY_CACHE_SIZE"), "%d", &query_cache_size) != 1) {
+        msSetError(MS_MISCERR, "Error reading value for processing key \"QUERY_CACHE_SIZE\"", "msQueryByRect()");
+        return MS_FAILURE;
+      }
+    }
+
     /* conditions may have changed since this layer last drawn, so set 
        layer->project true to recheck projection needs (Bug #673) */ 
     lp->project = MS_TRUE; 
@@ -557,7 +588,7 @@
       }	
 
       if(status == MS_TRUE)
-        addResult(lp->resultcache, &shape);
+        addResult(lp->resultcache, &shape, (lp->resultcache->numresults < query_cache_size ? MS_TRUE:MS_FALSE));
       msFreeShape(&shape);
     } /* next shape */
       
@@ -832,7 +863,7 @@
 	}
 
 	if(status == MS_TRUE)
-	  addResult(lp->resultcache, &shape);
+	  addResult(lp->resultcache, &shape, 0);
 
 	msFreeShape(&shape);
       } /* next shape */
@@ -1011,11 +1042,11 @@
       if( d <= t ) { /* found one */
 	if(mode == MS_SINGLE) {
 	  lp->resultcache->numresults = 0;
-	  addResult(lp->resultcache, &shape);
+	  addResult(lp->resultcache, &shape, 0);
 	  lp->resultcache->bounds = shape.bounds;
 	  t = d; /* next one must be closer */
 	} else {
-	  addResult(lp->resultcache, &shape);
+	  addResult(lp->resultcache, &shape, 0);
 	}
       }
  
@@ -1219,7 +1250,7 @@
       }
 
       if(status == MS_TRUE)
-	addResult(lp->resultcache, &shape);
+	addResult(lp->resultcache, &shape, 0);
 
       msFreeShape(&shape);
     } /* next shape */
@@ -1451,7 +1482,7 @@
         }
 
         if(status == MS_TRUE)
-          addResult(lp->resultcache, &shape);
+          addResult(lp->resultcache, &shape, 0);
 
         msFreeShape(&shape);
       } /* next shape */

Modified: sandbox/single-pass/mapserver/mapserver.h
===================================================================
--- sandbox/single-pass/mapserver/mapserver.h	2009-06-02 03:12:48 UTC (rev 9060)
+++ sandbox/single-pass/mapserver/mapserver.h	2009-06-02 04:17:18 UTC (rev 9061)
@@ -885,7 +885,7 @@
 /*                         resultCacheMemberObj                         */
 /************************************************************************/
 typedef struct {
-  long offset;
+  shapeObj *shape; /* can choose to cache the whole shape rather than just indexes */
   long shapeindex;
   int tileindex;
   int classindex;

Modified: sandbox/single-pass/mapserver/maptemplate.c
===================================================================
--- sandbox/single-pass/mapserver/maptemplate.c	2009-06-02 03:12:48 UTC (rev 9060)
+++ sandbox/single-pass/mapserver/maptemplate.c	2009-06-02 04:17:18 UTC (rev 9061)
@@ -862,7 +862,11 @@
 
   msLayerRewind(layer);
   for(i=0; i<limit; i++) {
-    status = msLayerGetShape(layer, &(mapserv->resultshape), layer->resultcache->results[i].tileindex, layer->resultcache->results[i].shapeindex);
+    if(layer->resultcache->results[i].shape) {
+      msCopyShape(layer->resultcache->results[i].shape, &(mapserv->resultshape));      
+      status = MS_SUCCESS;
+    } else
+      status = msLayerGetShape(layer, &(mapserv->resultshape), layer->resultcache->results[i].tileindex, layer->resultcache->results[i].shapeindex);
     if(status != MS_SUCCESS) return status;
 
     /* prepare any necessary JOINs here (one-to-one only) */
@@ -891,7 +895,7 @@
     free(tagInstance);
     msFreeShape(&(mapserv->resultshape)); /* init too */
 
-    i++; /* increment counters */
+    // i++; /* increment counters */
     mapserv->RN++;
     mapserv->LRN++;
   }



More information about the mapserver-commits mailing list