Skip to content

Commit 804ac7e

Browse files
committedMay 16, 2016
Avoid refreshing canvas for every joined feature
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) (cherry-picked from 22acf3b)
1 parent ad0b8f9 commit 804ac7e

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed
 

‎src/core/qgsvectorlayerfeatureiterator.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -685,12 +685,7 @@ void QgsVectorLayerFeatureIterator::FetchJoinInfo::addJoinedAttributesCached( Qg
685685
void QgsVectorLayerFeatureIterator::FetchJoinInfo::addJoinedAttributesDirect( QgsFeature& f, const QVariant& joinValue ) const
686686
{
687687
// no memory cache, query the joined values by setting substring
688-
QString subsetString = joinLayer->dataProvider()->subsetString(); // provider might already have a subset string
689-
QString bkSubsetString = subsetString;
690-
if ( !subsetString.isEmpty() )
691-
{
692-
subsetString.prepend( '(' ).append( ") AND " );
693-
}
688+
QString subsetString;
694689

695690
QString joinFieldName;
696691
if ( joinInfo->joinFieldName.isEmpty() && joinInfo->joinFieldIndex >= 0 && joinInfo->joinFieldIndex < joinLayer->fields().count() )
@@ -723,8 +718,6 @@ void QgsVectorLayerFeatureIterator::FetchJoinInfo::addJoinedAttributesDirect( Qg
723718
subsetString += '=' + v;
724719
}
725720

726-
joinLayer->dataProvider()->setSubsetString( subsetString, false );
727-
728721
// maybe user requested just a subset of layer's attributes
729722
// so we do not have to cache everything
730723
bool hasSubset = joinInfo->joinFieldNamesSubset();
@@ -736,6 +729,8 @@ void QgsVectorLayerFeatureIterator::FetchJoinInfo::addJoinedAttributesDirect( Qg
736729
QgsFeatureRequest request;
737730
request.setFlags( QgsFeatureRequest::NoGeometry );
738731
request.setSubsetOfAttributes( attributes );
732+
request.setFilterExpression( subsetString );
733+
request.setLimit( 1 );
739734
QgsFeatureIterator fi = joinLayer->getFeatures( request );
740735

741736
// get first feature
@@ -765,8 +760,6 @@ void QgsVectorLayerFeatureIterator::FetchJoinInfo::addJoinedAttributesDirect( Qg
765760
{
766761
// no suitable join feature found, keeping empty (null) attributes
767762
}
768-
769-
joinLayer->dataProvider()->setSubsetString( bkSubsetString, false );
770763
}
771764

772765

0 commit comments

Comments
 (0)
Please sign in to comment.