@@ -3418,7 +3418,7 @@ static QVariant fcnGetFeatureById( const QVariantList &values, const QgsExpressi
3418
3418
return result;
3419
3419
}
3420
3420
3421
- static QVariant fcnGetFeature ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
3421
+ static QVariant fcnGetFeature ( const QVariantList &values, const QgsExpressionContext *context , QgsExpression *parent, const QgsExpressionNodeFunction * )
3422
3422
{
3423
3423
// arguments: 1. layer id / name, 2. key attribute, 3. eq value
3424
3424
QgsVectorLayer *vl = QgsExpressionUtils::getVectorLayer ( values.at ( 0 ), parent );
@@ -3437,6 +3437,13 @@ static QVariant fcnGetFeature( const QVariantList &values, const QgsExpressionCo
3437
3437
}
3438
3438
3439
3439
const QVariant &attVal = values.at ( 2 );
3440
+
3441
+ const QString cacheValueKey = QStringLiteral ( " getfeature:%1:%2:%3" ).arg ( vl->id () ).arg ( attributeId ).arg ( attVal.toString () );
3442
+ if ( context && context->hasCachedValue ( cacheValueKey ) )
3443
+ {
3444
+ return context->cachedValue ( cacheValueKey );
3445
+ }
3446
+
3440
3447
QgsFeatureRequest req;
3441
3448
req.setFilterExpression ( QStringLiteral ( " %1=%2" ).arg ( QgsExpression::quotedColumnRef ( attribute ),
3442
3449
QgsExpression::quotedString ( attVal.toString () ) ) );
@@ -3448,10 +3455,15 @@ static QVariant fcnGetFeature( const QVariantList &values, const QgsExpressionCo
3448
3455
QgsFeatureIterator fIt = vl->getFeatures ( req );
3449
3456
3450
3457
QgsFeature fet;
3458
+ QVariant res;
3451
3459
if ( fIt .nextFeature ( fet ) )
3452
- return QVariant::fromValue ( fet );
3460
+ {
3461
+ res = QVariant::fromValue ( fet );
3462
+ }
3453
3463
3454
- return QVariant ();
3464
+ if ( context )
3465
+ context->setCachedValue ( cacheValueKey, res );
3466
+ return res;
3455
3467
}
3456
3468
3457
3469
static QVariant fcnRepresentValue ( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction *node )
@@ -3481,7 +3493,14 @@ static QVariant fcnRepresentValue( const QVariantList &values, const QgsExpressi
3481
3493
}
3482
3494
else
3483
3495
{
3484
- QgsVectorLayer *layer = QgsExpressionUtils::getVectorLayer ( context->variable ( " layer" ), parent );
3496
+ QgsVectorLayer *layer = QgsExpressionUtils::getVectorLayer ( context->variable ( QStringLiteral ( " layer" ) ), parent );
3497
+
3498
+ const QString cacheValueKey = QStringLiteral ( " repvalfcnval:%1:%2:%3" ).arg ( layer ? layer->id () : QStringLiteral ( " [None]" ), fieldName, value.toString () );
3499
+ if ( context->hasCachedValue ( cacheValueKey ) )
3500
+ {
3501
+ return context->cachedValue ( cacheValueKey );
3502
+ }
3503
+
3485
3504
const QgsEditorWidgetSetup setup = fields.at ( fieldIndex ).editorWidgetSetup ();
3486
3505
const QgsFieldFormatter *formatter = QgsApplication::fieldFormatterRegistry ()->fieldFormatter ( setup.type () );
3487
3506
@@ -3497,6 +3516,8 @@ static QVariant fcnRepresentValue( const QVariantList &values, const QgsExpressi
3497
3516
cache = context->cachedValue ( cacheKey );
3498
3517
3499
3518
result = formatter->representValue ( layer, fieldIndex, setup.config (), cache, value );
3519
+
3520
+ context->setCachedValue ( cacheValueKey, result );
3500
3521
}
3501
3522
}
3502
3523
else
0 commit comments