@@ -3462,7 +3462,7 @@ static QVariant fcnGetFeatureById( const QVariantList &values, const QgsExpressi
3462
3462
return result;
3463
3463
}
3464
3464
3465
- static QVariant fcnGetFeature ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
3465
+ static QVariant fcnGetFeature ( const QVariantList &values, const QgsExpressionContext *context , QgsExpression *parent, const QgsExpressionNodeFunction * )
3466
3466
{
3467
3467
// arguments: 1. layer id / name, 2. key attribute, 3. eq value
3468
3468
QgsVectorLayer *vl = QgsExpressionUtils::getVectorLayer ( values.at ( 0 ), parent );
@@ -3481,6 +3481,13 @@ static QVariant fcnGetFeature( const QVariantList &values, const QgsExpressionCo
3481
3481
}
3482
3482
3483
3483
const QVariant &attVal = values.at ( 2 );
3484
+
3485
+ const QString cacheValueKey = QStringLiteral ( " getfeature:%1:%2:%3" ).arg ( vl->id () ).arg ( attributeId ).arg ( attVal.toString () );
3486
+ if ( context && context->hasCachedValue ( cacheValueKey ) )
3487
+ {
3488
+ return context->cachedValue ( cacheValueKey );
3489
+ }
3490
+
3484
3491
QgsFeatureRequest req;
3485
3492
req.setFilterExpression ( QStringLiteral ( " %1=%2" ).arg ( QgsExpression::quotedColumnRef ( attribute ),
3486
3493
QgsExpression::quotedString ( attVal.toString () ) ) );
@@ -3492,10 +3499,15 @@ static QVariant fcnGetFeature( const QVariantList &values, const QgsExpressionCo
3492
3499
QgsFeatureIterator fIt = vl->getFeatures ( req );
3493
3500
3494
3501
QgsFeature fet;
3502
+ QVariant res;
3495
3503
if ( fIt .nextFeature ( fet ) )
3496
- return QVariant::fromValue ( fet );
3504
+ {
3505
+ res = QVariant::fromValue ( fet );
3506
+ }
3497
3507
3498
- return QVariant ();
3508
+ if ( context )
3509
+ context->setCachedValue ( cacheValueKey, res );
3510
+ return res;
3499
3511
}
3500
3512
3501
3513
static QVariant fcnRepresentValue ( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node )
@@ -3525,7 +3537,14 @@ static QVariant fcnRepresentValue( const QVariantList &values, const QgsExpressi
3525
3537
}
3526
3538
else
3527
3539
{
3528
- QgsVectorLayer *layer = QgsExpressionUtils::getVectorLayer ( context->variable ( " layer" ), parent );
3540
+ QgsVectorLayer *layer = QgsExpressionUtils::getVectorLayer ( context->variable ( QStringLiteral ( " layer" ) ), parent );
3541
+
3542
+ const QString cacheValueKey = QStringLiteral ( " repvalfcnval:%1:%2:%3" ).arg ( layer ? layer->id () : QStringLiteral ( " [None]" ), fieldName, value.toString () );
3543
+ if ( context->hasCachedValue ( cacheValueKey ) )
3544
+ {
3545
+ return context->cachedValue ( cacheValueKey );
3546
+ }
3547
+
3529
3548
const QgsEditorWidgetSetup setup = fields.at ( fieldIndex ).editorWidgetSetup ();
3530
3549
const QgsFieldFormatter *formatter = QgsApplication::fieldFormatterRegistry ()->fieldFormatter ( setup.type () );
3531
3550
@@ -3541,6 +3560,8 @@ static QVariant fcnRepresentValue( const QVariantList &values, const QgsExpressi
3541
3560
cache = context->cachedValue ( cacheKey );
3542
3561
3543
3562
result = formatter->representValue ( layer, fieldIndex, setup.config (), cache, value );
3563
+
3564
+ context->setCachedValue ( cacheValueKey, result );
3544
3565
}
3545
3566
}
3546
3567
else
0 commit comments