From dea8fe5741846926ed52003082359f0c0949e6da Mon Sep 17 00:00:00 2001 From: Favour Olayinka Date: Tue, 1 Oct 2024 11:42:03 +0100 Subject: [PATCH] 106a6 integration performance issues (#581) * apply performance fixes * fix integration * Update client/components/open/forms/components/FirstSubmissionModal.vue Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix unique cache for forms --------- Co-authored-by: Julien Nahum Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../Zapier/IntegrationController.php | 6 +- .../Handlers/AbstractIntegrationHandler.php | 11 +- .../forms/components/FirstSubmissionModal.vue | 108 ++++++++++++++++++ 3 files changed, 118 insertions(+), 7 deletions(-) create mode 100644 client/components/open/forms/components/FirstSubmissionModal.vue diff --git a/api/app/Http/Controllers/Integrations/Zapier/IntegrationController.php b/api/app/Http/Controllers/Integrations/Zapier/IntegrationController.php index 46235897..4a8b97b0 100644 --- a/api/app/Http/Controllers/Integrations/Zapier/IntegrationController.php +++ b/api/app/Http/Controllers/Integrations/Zapier/IntegrationController.php @@ -52,11 +52,15 @@ public function poll(PollSubmissionRequest $request) $this->authorize('view', $form); $lastSubmission = $form->submissions()->latest()->first(); + $submissionData = null; if (!$lastSubmission) { // Generate fake data when no previous submissions $submissionData = (new FormSubmissionDataFactory($form))->asFormSubmissionData()->createSubmissionData(); } + $cacheKey = "zapier-poll-submissions-{$form->id}"; + return (array) \Cache::remember($cacheKey, 60 * 5, function () use ($form, $submissionData, $lastSubmission) { + return [ZapierIntegration::formatWebhookData($form, $submissionData ?? $lastSubmission->data)]; + }); - return [ZapierIntegration::formatWebhookData($form, $submissionData ?? $lastSubmission->data)]; } } diff --git a/api/app/Integrations/Handlers/AbstractIntegrationHandler.php b/api/app/Integrations/Handlers/AbstractIntegrationHandler.php index 7d95ef05..47fc78cb 100644 --- a/api/app/Integrations/Handlers/AbstractIntegrationHandler.php +++ b/api/app/Integrations/Handlers/AbstractIntegrationHandler.php @@ -114,13 +114,12 @@ public static function formatWebhookData(Form $form, array $submissionData): arr // Old format - kept for retro-compatibility $oldFormatData = []; - foreach ($formatter->getFieldsWithValue() as $field) { - $oldFormatData[$field['name']] = $field['value']; - } - - // New format using ID $formattedData = []; - foreach ($formatter->getFieldsWithValue() as $field) { + $fieldsWithValue = $formatter->getFieldsWithValue(); + + foreach ($fieldsWithValue as $field) { + $oldFormatData[$field['name']] = $field['value']; + // New format using ID $formattedData[$field['id']] = [ 'value' => $field['value'], 'name' => $field['name'], diff --git a/client/components/open/forms/components/FirstSubmissionModal.vue b/client/components/open/forms/components/FirstSubmissionModal.vue new file mode 100644 index 00000000..25fbbf99 --- /dev/null +++ b/client/components/open/forms/components/FirstSubmissionModal.vue @@ -0,0 +1,108 @@ + + +