Skip to content

Commit 4a4dc6b

Browse files
committed
[QGIS-Server] Enhance config cache
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
1 parent fda637b commit 4a4dc6b

File tree

8 files changed

+179
-165
lines changed

8 files changed

+179
-165
lines changed

src/mapserver/qgsconfigcache.cpp

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,27 @@ QgsConfigCache::~QgsConfigCache()
4242

4343
QgsServerProjectParser* QgsConfigCache::serverConfiguration( const QString& filePath )
4444
{
45-
QDomDocument* doc = xmlDocument( filePath );
46-
return new QgsServerProjectParser( doc, filePath );
47-
}
48-
49-
QgsWCSProjectParser* QgsConfigCache::wcsConfiguration( const QString& filePath )
50-
{
51-
QgsWCSProjectParser* p = mWCSConfigCache.object( filePath );
45+
QgsServerProjectParser* p = mServerConfigCache.object( filePath );
5246
if ( !p )
5347
{
5448
QDomDocument* doc = xmlDocument( filePath );
5549
if ( !doc )
5650
{
5751
return 0;
5852
}
59-
p = new QgsWCSProjectParser( doc, filePath );
53+
p = new QgsServerProjectParser( doc, filePath );
54+
mServerConfigCache.insert( filePath, p );
55+
mFileSystemWatcher.addPath( filePath );
56+
}
57+
return p;
58+
}
59+
60+
QgsWCSProjectParser* QgsConfigCache::wcsConfiguration( const QString& filePath )
61+
{
62+
QgsWCSProjectParser* p = mWCSConfigCache.object( filePath );
63+
if ( !p )
64+
{
65+
p = new QgsWCSProjectParser( filePath );
6066
mWCSConfigCache.insert( filePath, p );
6167
mFileSystemWatcher.addPath( filePath );
6268
}
@@ -70,13 +76,7 @@ QgsWFSProjectParser* QgsConfigCache::wfsConfiguration( const QString& filePath )
7076
QgsWFSProjectParser* p = mWFSConfigCache.object( filePath );
7177
if ( !p )
7278
{
73-
QDomDocument* doc = xmlDocument( filePath );
74-
if ( !doc )
75-
{
76-
return 0;
77-
}
78-
79-
p = new QgsWFSProjectParser( doc, filePath );
79+
p = new QgsWFSProjectParser( filePath );
8080
mWFSConfigCache.insert( filePath, p );
8181
mFileSystemWatcher.addPath( filePath );
8282
}
@@ -105,7 +105,7 @@ QgsWMSConfigParser* QgsConfigCache::wmsConfiguration( const QString& filePath, c
105105
}
106106
else
107107
{
108-
p = new QgsWMSProjectParser( doc, filePath );
108+
p = new QgsWMSProjectParser( filePath );
109109
}
110110
mWMSConfigCache.insert( filePath, p );
111111
mFileSystemWatcher.addPath( filePath );
@@ -117,6 +117,12 @@ QgsWMSConfigParser* QgsConfigCache::wmsConfiguration( const QString& filePath, c
117117

118118
QDomDocument* QgsConfigCache::xmlDocument( const QString& filePath )
119119
{
120+
// first get cache
121+
QDomDocument* xmlDoc = mXmlDocumentCache.object( filePath );
122+
if ( xmlDoc )
123+
return xmlDoc;
124+
125+
// i it's first access
120126
//first open file
121127
QFile configFile( filePath );
122128
if ( !configFile.exists() )
@@ -132,7 +138,7 @@ QDomDocument* QgsConfigCache::xmlDocument( const QString& filePath )
132138
}
133139

134140
//then create xml document
135-
QDomDocument* xmlDoc = new QDomDocument();
141+
xmlDoc = new QDomDocument();
136142
QString errorMsg;
137143
int line, column;
138144
if ( !xmlDoc->setContent( &configFile, true, &errorMsg, &line, &column ) )
@@ -142,11 +148,14 @@ QDomDocument* QgsConfigCache::xmlDocument( const QString& filePath )
142148
delete xmlDoc;
143149
return 0;
144150
}
151+
mXmlDocumentCache.insert( filePath, xmlDoc );
145152
return xmlDoc;
146153
}
147154

148155
void QgsConfigCache::removeChangedEntry( const QString& path )
149156
{
157+
mXmlDocumentCache.remove( path );
158+
mServerConfigCache.remove( path );
150159
mWMSConfigCache.remove( path );
151160
mWFSConfigCache.remove( path );
152161
mWCSConfigCache.remove( path );

src/mapserver/qgsconfigcache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class QgsConfigCache: public QObject
5252
/**Returns xml document for project file / sld or 0 in case of errors*/
5353
QDomDocument* xmlDocument( const QString& filePath );
5454

55+
QCache<QString, QDomDocument> mXmlDocumentCache;
56+
QCache<QString, QgsServerProjectParser> mServerConfigCache;
5557
QCache<QString, QgsWMSConfigParser> mWMSConfigCache;
5658
QCache<QString, QgsWFSProjectParser> mWFSConfigCache;
5759
QCache<QString, QgsWCSProjectParser> mWCSConfigCache;

src/mapserver/qgswcsprojectparser.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717

1818
#include "qgswcsprojectparser.h"
1919
#include "qgsconfigparserutils.h"
20+
#include "qgsconfigcache.h"
2021
#include "qgsrasterlayer.h"
2122

22-
QgsWCSProjectParser::QgsWCSProjectParser( QDomDocument* xmlDoc, const QString& filePath ): mProjectParser( xmlDoc, filePath )
23+
QgsWCSProjectParser::QgsWCSProjectParser( const QString& filePath )
2324
{
25+
QgsServerProjectParser* mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
2426
}
2527

2628
QgsWCSProjectParser::~QgsWCSProjectParser()
@@ -29,19 +31,19 @@ QgsWCSProjectParser::~QgsWCSProjectParser()
2931

3032
void QgsWCSProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const
3133
{
32-
mProjectParser.serviceCapabilities( parentElement, doc, "WCS" );
34+
mProjectParser->serviceCapabilities( parentElement, doc, "WCS" );
3335
}
3436

3537
QString QgsWCSProjectParser::wcsServiceUrl() const
3638
{
3739
QString url;
3840

39-
if ( !mProjectParser.xmlDocument() )
41+
if ( !mProjectParser->xmlDocument() )
4042
{
4143
return url;
4244
}
4345

44-
QDomElement propertiesElem = mProjectParser.propertiesElem();
46+
QDomElement propertiesElem = mProjectParser->propertiesElem();
4547
if ( !propertiesElem.isNull() )
4648
{
4749
QDomElement wcsUrlElem = propertiesElem.firstChildElement( "WCSUrl" );
@@ -55,12 +57,12 @@ QString QgsWCSProjectParser::wcsServiceUrl() const
5557

5658
QString QgsWCSProjectParser::serviceUrl() const
5759
{
58-
return mProjectParser.serviceUrl();
60+
return mProjectParser->serviceUrl();
5961
}
6062

6163
void QgsWCSProjectParser::wcsContentMetadata( QDomElement& parentElement, QDomDocument& doc ) const
6264
{
63-
const QList<QDomElement>& projectLayerElements = mProjectParser.projectLayerElements();
65+
const QList<QDomElement>& projectLayerElements = mProjectParser->projectLayerElements();
6466
if ( projectLayerElements.size() < 1 )
6567
{
6668
return;
@@ -75,7 +77,7 @@ void QgsWCSProjectParser::wcsContentMetadata( QDomElement& parentElement, QDomDo
7577
QString type = elem.attribute( "type" );
7678
if ( type == "raster" )
7779
{
78-
QgsMapLayer *layer = mProjectParser.createLayerFromElement( elem );
80+
QgsMapLayer *layer = mProjectParser->createLayerFromElement( elem );
7981
if ( layer && wcsLayersId.contains( layer->id() ) )
8082
{
8183
QgsDebugMsg( QString( "add layer %1 to map" ).arg( layer->id() ) );
@@ -137,12 +139,12 @@ void QgsWCSProjectParser::wcsContentMetadata( QDomElement& parentElement, QDomDo
137139
QStringList QgsWCSProjectParser::wcsLayers() const
138140
{
139141
QStringList wcsList;
140-
if ( !mProjectParser.xmlDocument() )
142+
if ( !mProjectParser->xmlDocument() )
141143
{
142144
return wcsList;
143145
}
144146

145-
QDomElement propertiesElem = mProjectParser.propertiesElem();
147+
QDomElement propertiesElem = mProjectParser->propertiesElem();
146148
if ( propertiesElem.isNull() )
147149
{
148150
return wcsList;
@@ -162,7 +164,7 @@ QStringList QgsWCSProjectParser::wcsLayers() const
162164

163165
void QgsWCSProjectParser::describeCoverage( const QString& aCoveName, QDomElement& parentElement, QDomDocument& doc ) const
164166
{
165-
const QList<QDomElement>& projectLayerElements = mProjectParser.projectLayerElements();
167+
const QList<QDomElement>& projectLayerElements = mProjectParser->projectLayerElements();
166168
if ( projectLayerElements.size() < 1 )
167169
{
168170
return;
@@ -186,7 +188,7 @@ void QgsWCSProjectParser::describeCoverage( const QString& aCoveName, QDomElemen
186188
QString type = elem.attribute( "type" );
187189
if ( type == "raster" )
188190
{
189-
QgsMapLayer *layer = mProjectParser.createLayerFromElement( elem );
191+
QgsMapLayer *layer = mProjectParser->createLayerFromElement( elem );
190192
if ( !layer )
191193
continue;
192194
QString coveName = layer->name();
@@ -366,7 +368,7 @@ QList<QgsMapLayer*> QgsWCSProjectParser::mapLayerFromCoverage( const QString& cN
366368
{
367369
QList<QgsMapLayer*> layerList;
368370

369-
const QList<QDomElement>& projectLayerElements = mProjectParser.projectLayerElements();
371+
const QList<QDomElement>& projectLayerElements = mProjectParser->projectLayerElements();
370372
if ( projectLayerElements.size() < 1 )
371373
{
372374
return layerList;
@@ -379,7 +381,7 @@ QList<QgsMapLayer*> QgsWCSProjectParser::mapLayerFromCoverage( const QString& cN
379381
QString type = elem.attribute( "type" );
380382
if ( type == "raster" )
381383
{
382-
QgsMapLayer *mLayer = mProjectParser.createLayerFromElement( elem, useCache );
384+
QgsMapLayer *mLayer = mProjectParser->createLayerFromElement( elem, useCache );
383385
QgsRasterLayer* layer = dynamic_cast<QgsRasterLayer*>( mLayer );
384386
if ( !layer || !wcsLayersId.contains( layer->id() ) )
385387
return layerList;

src/mapserver/qgswcsprojectparser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
class QgsWCSProjectParser
2424
{
2525
public:
26-
QgsWCSProjectParser( QDomDocument* xmlDoc, const QString& filePath );
26+
QgsWCSProjectParser( const QString& filePath );
2727
~QgsWCSProjectParser();
2828

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

3737
private:
38-
QgsServerProjectParser mProjectParser;
38+
QgsServerProjectParser* mProjectParser;
3939
};
4040

4141
#endif // QGSWCSPROJECTPARSER_H

0 commit comments

Comments
 (0)