Skip to content

Commit

Permalink
[QGIS-Server] Enhance config cache
Browse files Browse the repository at this point in the history
Add xmlDocument and server config in cache

xmlDocument and server config will be opened once for every requested W*S
Every requested W*S will point to the same server config and xmlDocument
  • Loading branch information
rldhont committed Nov 15, 2014
1 parent fda637b commit 4a4dc6b
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 165 deletions.
43 changes: 26 additions & 17 deletions src/mapserver/qgsconfigcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,27 @@ QgsConfigCache::~QgsConfigCache()

QgsServerProjectParser* QgsConfigCache::serverConfiguration( const QString& filePath )
{
QDomDocument* doc = xmlDocument( filePath );
return new QgsServerProjectParser( doc, filePath );
}

QgsWCSProjectParser* QgsConfigCache::wcsConfiguration( const QString& filePath )
{
QgsWCSProjectParser* p = mWCSConfigCache.object( filePath );
QgsServerProjectParser* p = mServerConfigCache.object( filePath );
if ( !p )
{
QDomDocument* doc = xmlDocument( filePath );
if ( !doc )
{
return 0;
}
p = new QgsWCSProjectParser( doc, filePath );
p = new QgsServerProjectParser( doc, filePath );
mServerConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
}
return p;
}

QgsWCSProjectParser* QgsConfigCache::wcsConfiguration( const QString& filePath )
{
QgsWCSProjectParser* p = mWCSConfigCache.object( filePath );
if ( !p )
{
p = new QgsWCSProjectParser( filePath );
mWCSConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
}
Expand All @@ -70,13 +76,7 @@ QgsWFSProjectParser* QgsConfigCache::wfsConfiguration( const QString& filePath )
QgsWFSProjectParser* p = mWFSConfigCache.object( filePath );
if ( !p )
{
QDomDocument* doc = xmlDocument( filePath );
if ( !doc )
{
return 0;
}

p = new QgsWFSProjectParser( doc, filePath );
p = new QgsWFSProjectParser( filePath );
mWFSConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
}
Expand Down Expand Up @@ -105,7 +105,7 @@ QgsWMSConfigParser* QgsConfigCache::wmsConfiguration( const QString& filePath, c
}
else
{
p = new QgsWMSProjectParser( doc, filePath );
p = new QgsWMSProjectParser( filePath );
}
mWMSConfigCache.insert( filePath, p );
mFileSystemWatcher.addPath( filePath );
Expand All @@ -117,6 +117,12 @@ QgsWMSConfigParser* QgsConfigCache::wmsConfiguration( const QString& filePath, c

QDomDocument* QgsConfigCache::xmlDocument( const QString& filePath )
{
// first get cache
QDomDocument* xmlDoc = mXmlDocumentCache.object( filePath );
if ( xmlDoc )
return xmlDoc;

// i it's first access
//first open file
QFile configFile( filePath );
if ( !configFile.exists() )
Expand All @@ -132,7 +138,7 @@ QDomDocument* QgsConfigCache::xmlDocument( const QString& filePath )
}

//then create xml document
QDomDocument* xmlDoc = new QDomDocument();
xmlDoc = new QDomDocument();
QString errorMsg;
int line, column;
if ( !xmlDoc->setContent( &configFile, true, &errorMsg, &line, &column ) )
Expand All @@ -142,11 +148,14 @@ QDomDocument* QgsConfigCache::xmlDocument( const QString& filePath )
delete xmlDoc;
return 0;
}
mXmlDocumentCache.insert( filePath, xmlDoc );
return xmlDoc;
}

void QgsConfigCache::removeChangedEntry( const QString& path )
{
mXmlDocumentCache.remove( path );
mServerConfigCache.remove( path );
mWMSConfigCache.remove( path );
mWFSConfigCache.remove( path );
mWCSConfigCache.remove( path );
Expand Down
2 changes: 2 additions & 0 deletions src/mapserver/qgsconfigcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class QgsConfigCache: public QObject
/**Returns xml document for project file / sld or 0 in case of errors*/
QDomDocument* xmlDocument( const QString& filePath );

QCache<QString, QDomDocument> mXmlDocumentCache;
QCache<QString, QgsServerProjectParser> mServerConfigCache;
QCache<QString, QgsWMSConfigParser> mWMSConfigCache;
QCache<QString, QgsWFSProjectParser> mWFSConfigCache;
QCache<QString, QgsWCSProjectParser> mWCSConfigCache;
Expand Down
28 changes: 15 additions & 13 deletions src/mapserver/qgswcsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

#include "qgswcsprojectparser.h"
#include "qgsconfigparserutils.h"
#include "qgsconfigcache.h"
#include "qgsrasterlayer.h"

QgsWCSProjectParser::QgsWCSProjectParser( QDomDocument* xmlDoc, const QString& filePath ): mProjectParser( xmlDoc, filePath )
QgsWCSProjectParser::QgsWCSProjectParser( const QString& filePath )
{
QgsServerProjectParser* mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
}

QgsWCSProjectParser::~QgsWCSProjectParser()
Expand All @@ -29,19 +31,19 @@ QgsWCSProjectParser::~QgsWCSProjectParser()

void QgsWCSProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
{
mProjectParser.serviceCapabilities( parentElement, doc, "WCS" );
mProjectParser->serviceCapabilities( parentElement, doc, "WCS" );
}

QString QgsWCSProjectParser::wcsServiceUrl() const
{
QString url;

if ( !mProjectParser.xmlDocument() )
if ( !mProjectParser->xmlDocument() )
{
return url;
}

QDomElement propertiesElem = mProjectParser.propertiesElem();
QDomElement propertiesElem = mProjectParser->propertiesElem();
if ( !propertiesElem.isNull() )
{
QDomElement wcsUrlElem = propertiesElem.firstChildElement( "WCSUrl" );
Expand All @@ -55,12 +57,12 @@ QString QgsWCSProjectParser::wcsServiceUrl() const

QString QgsWCSProjectParser::serviceUrl() const
{
return mProjectParser.serviceUrl();
return mProjectParser->serviceUrl();
}

void QgsWCSProjectParser::wcsContentMetadata( QDomElement& parentElement, QDomDocument& doc ) const
{
const QList<QDomElement>& projectLayerElements = mProjectParser.projectLayerElements();
const QList<QDomElement>& projectLayerElements = mProjectParser->projectLayerElements();
if ( projectLayerElements.size() < 1 )
{
return;
Expand All @@ -75,7 +77,7 @@ void QgsWCSProjectParser::wcsContentMetadata( QDomElement& parentElement, QDomDo
QString type = elem.attribute( "type" );
if ( type == "raster" )
{
QgsMapLayer *layer = mProjectParser.createLayerFromElement( elem );
QgsMapLayer *layer = mProjectParser->createLayerFromElement( elem );
if ( layer && wcsLayersId.contains( layer->id() ) )
{
QgsDebugMsg( QString( "add layer %1 to map" ).arg( layer->id() ) );
Expand Down Expand Up @@ -137,12 +139,12 @@ void QgsWCSProjectParser::wcsContentMetadata( QDomElement& parentElement, QDomDo
QStringList QgsWCSProjectParser::wcsLayers() const
{
QStringList wcsList;
if ( !mProjectParser.xmlDocument() )
if ( !mProjectParser->xmlDocument() )
{
return wcsList;
}

QDomElement propertiesElem = mProjectParser.propertiesElem();
QDomElement propertiesElem = mProjectParser->propertiesElem();
if ( propertiesElem.isNull() )
{
return wcsList;
Expand All @@ -162,7 +164,7 @@ QStringList QgsWCSProjectParser::wcsLayers() const

void QgsWCSProjectParser::describeCoverage( const QString& aCoveName, QDomElement& parentElement, QDomDocument& doc ) const
{
const QList<QDomElement>& projectLayerElements = mProjectParser.projectLayerElements();
const QList<QDomElement>& projectLayerElements = mProjectParser->projectLayerElements();
if ( projectLayerElements.size() < 1 )
{
return;
Expand All @@ -186,7 +188,7 @@ void QgsWCSProjectParser::describeCoverage( const QString& aCoveName, QDomElemen
QString type = elem.attribute( "type" );
if ( type == "raster" )
{
QgsMapLayer *layer = mProjectParser.createLayerFromElement( elem );
QgsMapLayer *layer = mProjectParser->createLayerFromElement( elem );
if ( !layer )
continue;
QString coveName = layer->name();
Expand Down Expand Up @@ -366,7 +368,7 @@ QList<QgsMapLayer*> QgsWCSProjectParser::mapLayerFromCoverage( const QString& cN
{
QList<QgsMapLayer*> layerList;

const QList<QDomElement>& projectLayerElements = mProjectParser.projectLayerElements();
const QList<QDomElement>& projectLayerElements = mProjectParser->projectLayerElements();
if ( projectLayerElements.size() < 1 )
{
return layerList;
Expand All @@ -379,7 +381,7 @@ QList<QgsMapLayer*> QgsWCSProjectParser::mapLayerFromCoverage( const QString& cN
QString type = elem.attribute( "type" );
if ( type == "raster" )
{
QgsMapLayer *mLayer = mProjectParser.createLayerFromElement( elem, useCache );
QgsMapLayer *mLayer = mProjectParser->createLayerFromElement( elem, useCache );
QgsRasterLayer* layer = dynamic_cast<QgsRasterLayer*>( mLayer );
if ( !layer || !wcsLayersId.contains( layer->id() ) )
return layerList;
Expand Down
4 changes: 2 additions & 2 deletions src/mapserver/qgswcsprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class QgsWCSProjectParser
{
public:
QgsWCSProjectParser( QDomDocument* xmlDoc, const QString& filePath );
QgsWCSProjectParser( const QString& filePath );
~QgsWCSProjectParser();

void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;
Expand All @@ -35,7 +35,7 @@ class QgsWCSProjectParser
QList<QgsMapLayer*> mapLayerFromCoverage( const QString& cName, bool useCache = true ) const;

private:
QgsServerProjectParser mProjectParser;
QgsServerProjectParser* mProjectParser;
};

#endif // QGSWCSPROJECTPARSER_H
Loading

0 comments on commit 4a4dc6b

Please sign in to comment.