[mapguide-commits] r6201 - trunk/MgDev/Web/src/schemareport
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Mon Nov 7 07:13:28 EST 2011
Author: jng
Date: 2011-11-07 04:13:28 -0800 (Mon, 07 Nov 2011)
New Revision: 6201
Modified:
trunk/MgDev/Web/src/schemareport/showgeom.php
Log:
Schema Report performance improvement: Actually try to see if the Count() aggregate function is supported. This is much faster than raw spinning a feature reader.
Modified: trunk/MgDev/Web/src/schemareport/showgeom.php
===================================================================
--- trunk/MgDev/Web/src/schemareport/showgeom.php 2011-11-07 11:01:06 UTC (rev 6200)
+++ trunk/MgDev/Web/src/schemareport/showgeom.php 2011-11-07 12:13:28 UTC (rev 6201)
@@ -75,11 +75,59 @@
$geomProp = $classDef->GetProperties()->GetItem($geomName);
$spatialContext = $geomProp->GetSpatialContextAssociation();
- $featureReader = $featureSrvc->SelectFeatures($featuresId, $featureName, null);
- while($featureReader->ReadNext())
- $totalEntries++;
- $featureReader->Close();
-
+ //Try the SelectAggregate shortcut. This is faster than raw spinning a feature reader
+ //
+ //NOTE: If MapGuide supported scrollable readers like FDO, we'd have also tried
+ //that as well.
+ $canCount = false;
+ $gotCount = false;
+ $fsBr = $resourceSrvc->GetResourceContent($featuresId);
+ $fsXml = $fsBr->ToString();
+ $fsDoc = DOMDocument::loadXML($fsXml);
+ $providerNodeList = $fsDoc->getElementsByTagName("Provider");
+ $providerName = $providerNodeList->item(0)->nodeValue;
+ $capsBr = $featureSrvc->GetCapabilities($providerName);
+ $capsXml = $capsBr->ToString();
+ //This should be good enough to find out if Count() is supported
+ $canCount = !(strstr($capsXml, "<Name>Count</Name>") === false);
+
+ if ($canCount) {
+ $clsDef = $featureSrvc->GetClassDefinition($featuresId, $schemaName, $className);
+ $idProps = $clsDef->GetIdentityProperties();
+ if ($idProps->GetCount() > 0)
+ {
+ $pd = $idProps->GetItem(0);
+ $expr = "COUNT(" .$pd->GetName(). ")";
+ $query = new MgFeatureAggregateOptions();
+ $query->AddComputedProperty("TotalCount", $expr);
+ $dataReader = $featureSrvc->SelectAggregate($featuresId, $featureName, $query);
+ if ($dataReader->ReadNext())
+ {
+ $ptype = $dataReader->GetPropertyType("TotalCount");
+ switch ($ptype)
+ {
+ case MgPropertyType::Int32:
+ $totalEntries = $dataReader->GetInt32("TotalCount");
+ $gotCount = true;
+ break;
+ case MgPropertyType::Int64:
+ $totalEntries = $dataReader->GetInt64("TotalCount");
+ $gotCount = true;
+ break;
+ }
+ $dataReader->Close();
+ }
+ }
+ }
+
+ if ($gotCount == false)
+ {
+ $featureReader = $featureSrvc->SelectFeatures($featuresId, $featureName, null);
+ while($featureReader->ReadNext())
+ $totalEntries++;
+ $featureReader->Close();
+ }
+
// Create a layer definition
$layerfactory = new LayerDefinitionFactory();
$layerDefinition = CreateLayerDef($layerfactory, $resName, $featureName, $geomName, $geomType);
@@ -199,6 +247,7 @@
{
$validSession = 0;
echo $mge->GetExceptionMessage();
+ echo $mge->GetStackTrace();
}
catch (Exception $e)
{
More information about the mapguide-commits
mailing list