Skip to content
Permalink
Browse files

[layouts] Fix inefficient filtering in attribute tables

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 3, 2019
1 parent 899dcbf commit e3c1d18f3aaaab04adfec1af58419eb0419fb004
Showing with 3 additions and 2 deletions.
  1. +3 −2 src/core/layout/qgslayoutitemattributetable.cpp
@@ -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;
@@ -408,6 +410,7 @@ bool QgsLayoutItemAttributeTable::getTableContents( QgsLayoutTableContents &cont
if ( !filterExpression->hasParserError() )
{
activeFilter = true;
req.setFilterExpression( mFeatureFilter );
}
}

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

QgsFeatureRequest req;

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

0 comments on commit e3c1d18

Please sign in to comment.
You can’t perform that action at this time.