Skip to content

Commit e0fc9a9

Browse files
committed
Use FilterExpression request for get_feature expression function
Makes the function magnitudes faster for Postgres layers where the expression is compiled and can take advantage of Postgres indexes on the layer.
1 parent 6772ffb commit e0fc9a9

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/core/qgsexpression.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,20 +2033,18 @@ static QVariant fcnGetFeature( const QVariantList& values, const QgsExpressionCo
20332033

20342034
const QVariant& attVal = values.at( 2 );
20352035
QgsFeatureRequest req;
2036+
req.setFilterExpression( QString( "%1=%2" ).arg( QgsExpression::quotedColumnRef( attribute ),
2037+
QgsExpression::quotedString( attVal.toString() ) ) );
20362038
if ( !parent->needsGeometry() )
20372039
{
20382040
req.setFlags( QgsFeatureRequest::NoGeometry );
20392041
}
20402042
QgsFeatureIterator fIt = vl->getFeatures( req );
20412043

20422044
QgsFeature fet;
2043-
while ( fIt.nextFeature( fet ) )
2044-
{
2045-
if ( fet.attribute( attributeId ) == attVal )
2046-
{
2047-
return QVariant::fromValue( fet );
2048-
}
2049-
}
2045+
if ( fIt.nextFeature( fet ) )
2046+
return QVariant::fromValue( fet );
2047+
20502048
return QVariant();
20512049
}
20522050

0 commit comments

Comments
 (0)