Skip to content

Commit 29b8853

Browse files
committedAug 5, 2017
[postgis] Cache unknown CRS information
CRS information is queried when setting up a new feature source. This happens on the main thread (read: blocking). With this patch, at least this only happens once per srid.
1 parent a3bd321 commit 29b8853

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed
 

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3950,9 +3950,21 @@ QgsCoordinateReferenceSystem QgsPostgresProvider::crs() const
39503950
srs.createFromSrid( srid );
39513951
if ( !srs.isValid() )
39523952
{
3953-
QgsPostgresResult result( connectionRO()->PQexec( QStringLiteral( "SELECT proj4text FROM spatial_ref_sys WHERE srid=%1" ).arg( srid ) ) );
3954-
if ( result.PQresultStatus() == PGRES_TUPLES_OK )
3955-
srs = QgsCoordinateReferenceSystem::fromProj4( result.PQgetvalue( 0, 0 ) );
3953+
static QMap<int, QgsCoordinateReferenceSystem> sCrsCache;
3954+
if ( sCrsCache.contains( srid ) )
3955+
srs = sCrsCache.value( srid );
3956+
else
3957+
{
3958+
QgsPostgresConn *conn = connectionRO();
3959+
conn->lock();
3960+
QgsPostgresResult result( conn->PQexec( QStringLiteral( "SELECT proj4text FROM spatial_ref_sys WHERE srid=%1" ).arg( srid ) ) );
3961+
conn->unlock();
3962+
if ( result.PQresultStatus() == PGRES_TUPLES_OK )
3963+
{
3964+
srs = QgsCoordinateReferenceSystem::fromProj4( result.PQgetvalue( 0, 0 ) );
3965+
sCrsCache.insert( srid, srs );
3966+
}
3967+
}
39563968
}
39573969
return srs;
39583970
}

0 commit comments

Comments
 (0)
Please sign in to comment.