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

(cherry picked from commit e3c1d18)
  • Loading branch information
nyalldawson committed Jan 6, 2019
1 parent 06f6965 commit cf410407da9d4a3268e3de36517e3562ec7660d6
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 cf41040

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