Skip to content

Commit

Permalink
[layouts] Fix inefficient filtering in attribute tables
Browse files Browse the repository at this point in the history
Set the expression filter on the request itself, rather than looping
through all features and testing on the filter. This allows providers
to hand off the filtering to the underlying datasource, and utilise
indices/etc where available.

Fixes #20908
  • Loading branch information
nyalldawson committed Jan 4, 2019
1 parent 899dcbf commit e3c1d18
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/core/layout/qgslayoutitemattributetable.cpp
Expand Up @@ -399,6 +399,8 @@ bool QgsLayoutItemAttributeTable::getTableContents( QgsLayoutTableContents &cont
QgsExpressionContext context = createExpressionContext();
context.setFields( layer->fields() );

QgsFeatureRequest req;

//prepare filter expression
std::unique_ptr<QgsExpression> filterExpression;
bool activeFilter = false;
Expand All @@ -408,6 +410,7 @@ bool QgsLayoutItemAttributeTable::getTableContents( QgsLayoutTableContents &cont
if ( !filterExpression->hasParserError() )
{
activeFilter = true;
req.setFilterExpression( mFeatureFilter );
}
}

Expand All @@ -431,8 +434,6 @@ bool QgsLayoutItemAttributeTable::getTableContents( QgsLayoutTableContents &cont
}
}

QgsFeatureRequest req;

if ( mSource == QgsLayoutItemAttributeTable::RelationChildren )
{
QgsRelation relation = mLayout->project()->relationManager()->relation( mRelationId );
Expand Down

0 comments on commit e3c1d18

Please sign in to comment.