Skip to content

Commit

Permalink
Merge pull request #42412 from elpaso/optimization-ogr-avoid-double-l…
Browse files Browse the repository at this point in the history
…oad-fields-call

Prevent double expensive calls to loadFields in OGR
  • Loading branch information
elpaso authored and nyalldawson committed Mar 26, 2021
1 parent 924c70d commit 6943e4e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/core/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -2306,6 +2306,8 @@ bool QgsOgrProvider::_setSubsetString( const QString &theSQL, bool updateFeature
if ( theSQL == mSubsetString && mFeaturesCounted != QgsVectorDataProvider::Uncounted )
return true;

const bool subsetStringHasChanged { theSQL != mSubsetString };

if ( !theSQL.isEmpty() )
{
QMutex *mutex = nullptr;
Expand Down Expand Up @@ -2387,10 +2389,11 @@ bool QgsOgrProvider::_setSubsetString( const QString &theSQL, bool updateFeature

mRefreshFeatureCount = updateFeatureCount;

// check the validity of the layer
QgsDebugMsgLevel( QStringLiteral( "checking validity" ), 4 );
loadFields();
QgsDebugMsgLevel( QStringLiteral( "Done checking validity" ), 4 );
// check the validity of the layer if subset string has changed
if ( subsetStringHasChanged )
{
loadFields();
}

invalidateCachedExtent( false );

Expand Down Expand Up @@ -7340,4 +7343,3 @@ QgsProviderMetadata::ProviderCapabilities QgsOgrProviderMetadata::providerCapabi
return FileBasedUris;
}
///@endcond

0 comments on commit 6943e4e

Please sign in to comment.