Skip to content

Commit

Permalink
Avoid refreshing canvas for every joined feature
Browse files Browse the repository at this point in the history
Instead of setting the provider's subsetString to fetch joined
features, use a feature request with FilterExpression instead.
(Setting the subsetString results in a canvas refresh.)

Performance should be similar (if expression compilation is
enabled) and this also has the advantage of avoiding provider-
specific behaviour (eg case insensitive matching).

(fix #14800)
  • Loading branch information
nyalldawson committed May 10, 2016
1 parent 11a5a69 commit 22acf3b
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/core/qgsvectorlayerfeatureiterator.cpp
Expand Up @@ -690,12 +690,7 @@ void QgsVectorLayerFeatureIterator::FetchJoinInfo::addJoinedAttributesCached( Qg
void QgsVectorLayerFeatureIterator::FetchJoinInfo::addJoinedAttributesDirect( QgsFeature& f, const QVariant& joinValue ) const
{
// no memory cache, query the joined values by setting substring
QString subsetString = joinLayer->dataProvider()->subsetString(); // provider might already have a subset string
QString bkSubsetString = subsetString;
if ( !subsetString.isEmpty() )
{
subsetString.prepend( '(' ).append( ") AND " );
}
QString subsetString;

QString joinFieldName;
if ( joinInfo->joinFieldName.isEmpty() && joinInfo->joinFieldIndex >= 0 && joinInfo->joinFieldIndex < joinLayer->fields().count() )
Expand Down Expand Up @@ -728,8 +723,6 @@ void QgsVectorLayerFeatureIterator::FetchJoinInfo::addJoinedAttributesDirect( Qg
subsetString += '=' + v;
}

joinLayer->dataProvider()->setSubsetString( subsetString, false );

// maybe user requested just a subset of layer's attributes
// so we do not have to cache everything
bool hasSubset = joinInfo->joinFieldNamesSubset();
Expand All @@ -741,6 +734,8 @@ void QgsVectorLayerFeatureIterator::FetchJoinInfo::addJoinedAttributesDirect( Qg
QgsFeatureRequest request;
request.setFlags( QgsFeatureRequest::NoGeometry );
request.setSubsetOfAttributes( attributes );
request.setFilterExpression( subsetString );
request.setLimit( 1 );
QgsFeatureIterator fi = joinLayer->getFeatures( request );

// get first feature
Expand Down Expand Up @@ -770,8 +765,6 @@ void QgsVectorLayerFeatureIterator::FetchJoinInfo::addJoinedAttributesDirect( Qg
{
// no suitable join feature found, keeping empty (null) attributes
}

joinLayer->dataProvider()->setSubsetString( bkSubsetString, false );
}


Expand Down

0 comments on commit 22acf3b

Please sign in to comment.