From 2143dbd24f72dd3fec35a760604af4e0d32b3d5b Mon Sep 17 00:00:00 2001 From: Josh Crawford Date: Wed, 28 Aug 2024 23:25:38 +1000 Subject: [PATCH] FIx an edge-case with variables, where cached data matched against incorrect submission values --- src/helpers/Variables.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/helpers/Variables.php b/src/helpers/Variables.php index 21063073..27d077cd 100644 --- a/src/helpers/Variables.php +++ b/src/helpers/Variables.php @@ -180,9 +180,16 @@ public static function getParsedValue(mixed $value, Submission $submission = nul // Parse aliases and env variables $value = App::parseEnv($value); - // Use a cache key based on the submission, or few unsaved submissions, the formId + // Use a cache key based on the submission, or for unsaved submissions - the formId. + // Be sure to prefix things by what they are to prevent ID collision between form/submission elements. // This helps to only cache it per-submission, when being run in queues. - $cacheKey = $submission->id ?? $form->id ?? mt_rand(); + $cacheKey = mt_rand(); + + if ($submission->id) { + $cacheKey = 'submission' . $submission->id; + } else if ($form->id) { + $cacheKey = 'form' . $form->id; + } // Check to see if we have these already calculated for the request and submission // Just saves a good bunch of calculating values like looping through fields