Skip to content

Commit

Permalink
Higher limit for number of layers in WMS project, use hash instead of…
Browse files Browse the repository at this point in the history
… map in layer cache

git-svn-id: http://svn.osgeo.org/qgis/trunk@15260 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Feb 24, 2011
1 parent c2873ca commit f5b1607
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/mapserver/qgsmslayercache.cpp
Expand Up @@ -19,7 +19,8 @@
#include "qgsvectorlayer.h" #include "qgsvectorlayer.h"
#include "qgsmapserverlogger.h" #include "qgsmapserverlogger.h"


#define MAX_N_LAYERS 50 //maximum number of layers in the cache (and upper limit for layers in one published project)
#define MAX_N_LAYERS 100


QgsMSLayerCache* QgsMSLayerCache::mInstance = 0; QgsMSLayerCache* QgsMSLayerCache::mInstance = 0;


Expand All @@ -40,7 +41,7 @@ QgsMSLayerCache::QgsMSLayerCache()
QgsMSLayerCache::~QgsMSLayerCache() QgsMSLayerCache::~QgsMSLayerCache()
{ {
QgsMSDebugMsg( "removing all entries" ); QgsMSDebugMsg( "removing all entries" );
QMap<QPair<QString, QString>, QgsMSLayerCacheEntry>::iterator it; QHash<QPair<QString, QString>, QgsMSLayerCacheEntry>::iterator it;
for ( it = mEntries.begin(); it != mEntries.end(); ++it ) for ( it = mEntries.begin(); it != mEntries.end(); ++it )
{ {
delete it->layerPointer; delete it->layerPointer;
Expand All @@ -57,7 +58,7 @@ void QgsMSLayerCache::insertLayer( const QString& url, const QString& layerName,
} }


QPair<QString, QString> urlLayerPair = qMakePair( url, layerName ); QPair<QString, QString> urlLayerPair = qMakePair( url, layerName );
QMap<QPair<QString, QString>, QgsMSLayerCacheEntry>::iterator it = mEntries.find( urlLayerPair ); QHash<QPair<QString, QString>, QgsMSLayerCacheEntry>::iterator it = mEntries.find( urlLayerPair );
if ( it != mEntries.end() ) if ( it != mEntries.end() )
{ {
delete it->layerPointer; delete it->layerPointer;
Expand All @@ -76,7 +77,7 @@ void QgsMSLayerCache::insertLayer( const QString& url, const QString& layerName,
QgsMapLayer* QgsMSLayerCache::searchLayer( const QString& url, const QString& layerName ) QgsMapLayer* QgsMSLayerCache::searchLayer( const QString& url, const QString& layerName )
{ {
QPair<QString, QString> urlNamePair = qMakePair( url, layerName ); QPair<QString, QString> urlNamePair = qMakePair( url, layerName );
QMap<QPair<QString, QString>, QgsMSLayerCacheEntry>::iterator it = mEntries.find( urlNamePair ); QHash<QPair<QString, QString>, QgsMSLayerCacheEntry>::iterator it = mEntries.find( urlNamePair );
if ( it == mEntries.end() ) if ( it == mEntries.end() )
{ {
QgsMSDebugMsg( "Layer not found in cache" ); QgsMSDebugMsg( "Layer not found in cache" );
Expand Down Expand Up @@ -121,8 +122,8 @@ void QgsMSLayerCache::removeLeastUsedEntry()
return; return;
} }
QgsMSDebugMsg( "removeLeastUsedEntry" ); QgsMSDebugMsg( "removeLeastUsedEntry" );
QMap<QPair<QString, QString>, QgsMSLayerCacheEntry>::iterator it = mEntries.begin(); QHash<QPair<QString, QString>, QgsMSLayerCacheEntry>::iterator it = mEntries.begin();
QMap<QPair<QString, QString>, QgsMSLayerCacheEntry>::iterator lowest_it = it; QHash<QPair<QString, QString>, QgsMSLayerCacheEntry>::iterator lowest_it = it;
time_t lowest_time = it->lastUsedTime; time_t lowest_time = it->lastUsedTime;


for ( ; it != mEntries.end(); ++it ) for ( ; it != mEntries.end(); ++it )
Expand Down
4 changes: 2 additions & 2 deletions src/mapserver/qgsmslayercache.h
Expand Up @@ -19,7 +19,7 @@
#define QGSMSLAYERCACHE_H #define QGSMSLAYERCACHE_H


#include <time.h> #include <time.h>
#include <QMap> #include <QHash>
#include <QPair> #include <QPair>
#include <QString> #include <QString>


Expand Down Expand Up @@ -69,7 +69,7 @@ class QgsMSLayerCache
/**Cash entries with pair url/layer name as a key. The layer name is necessary for cases where the same /**Cash entries with pair url/layer name as a key. The layer name is necessary for cases where the same
url is used several time in a request. It ensures that different layer instances are created for different url is used several time in a request. It ensures that different layer instances are created for different
layer names*/ layer names*/
QMap<QPair<QString, QString>, QgsMSLayerCacheEntry> mEntries; QHash<QPair<QString, QString>, QgsMSLayerCacheEntry> mEntries;
}; };


#endif #endif

0 comments on commit f5b1607

Please sign in to comment.