From dc079f0d8d006af565d9d1a432a2855ec6dec1b4 Mon Sep 17 00:00:00 2001 From: Hetu Nandu Date: Wed, 26 Mar 2025 12:21:56 +0530 Subject: [PATCH] fix: Avoid excessive API saves (#39908) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description When we load API editor, we notice an update call without any changes. This happens because of the Headers and Params of the API editor adding empty key value fields. These fields are removed by the RestAPITransformer but the save keeps happening and we update the action state without the empty fields. When we load the API again, the API editor notices that no fields exists and adds them back again. This thus lead to excessive saves of the API to the server without any benefit. We will now check for this case before hand and avoid starting a save when form adds these empty key value fields ## Automation /ok-to-test tags="@tag.Datasource" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: b11f85f3ee716b2042331a55b670e292516755d6 > Cypress dashboard. > Tags: `@tag.Datasource` > Spec: >
Wed, 26 Mar 2025 05:59:23 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No ## Summary by CodeRabbit - **Bug Fixes** - Refined API action updates by filtering out empty entries during save operations, ensuring only valid data is processed and improving overall data integrity. - **New Features** - Introduced a utility function to check for empty key-value pairs, enhancing the logic for action property updates. --- app/client/src/sagas/ActionSagas.ts | 8 +++++++- app/client/src/utils/helpers.tsx | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/client/src/sagas/ActionSagas.ts b/app/client/src/sagas/ActionSagas.ts index 9f16b68abd..42ab890dcf 100644 --- a/app/client/src/sagas/ActionSagas.ts +++ b/app/client/src/sagas/ActionSagas.ts @@ -129,7 +129,7 @@ import { convertToBaseParentEntityIdSelector } from "selectors/pageListSelectors import AppsmithConsole from "utils/AppsmithConsole"; import { getDynamicBindingsChangesSaga } from "utils/DynamicBindingUtils"; import { getDefaultTemplateActionConfig } from "utils/editorContextUtils"; -import { shouldBeDefined } from "utils/helpers"; +import { isEmptyKeyValue, shouldBeDefined } from "utils/helpers"; import history from "utils/history"; import { setAIPromptTriggered } from "utils/storage"; import { sendAnalyticsEventSaga } from "./AnalyticsSaga"; @@ -1029,6 +1029,12 @@ export function* setActionPropertySaga( return; } + // The Rest Api editor adds empty key value pairs in the form for display. + // We don't need to save those empty key value pairs. + if (actionObj?.pluginType === PluginType.API && isEmptyKeyValue(value)) { + return; + } + //skipSave property is added to skip API calls when the updateAction needs to be called from the caller if (!skipSave) yield put(updateAction({ id: actionId })); } diff --git a/app/client/src/utils/helpers.tsx b/app/client/src/utils/helpers.tsx index b351bc44d9..948615ea79 100644 --- a/app/client/src/utils/helpers.tsx +++ b/app/client/src/utils/helpers.tsx @@ -44,6 +44,7 @@ import { klona as klonaLite } from "klona/lite"; import { klona as klonaJson } from "klona/json"; import { startAndEndSpanForFn } from "instrumentation/generateTraces"; +import type { Property } from "entities/Action"; export const snapToGrid = ( columnWidth: number, @@ -1301,3 +1302,15 @@ export function getDomainFromEmail(email: string) { return final_domain; } + +export function isEmptyKeyValue(value: Property | Property[]): boolean { + if (Array.isArray(value)) { + return value.every((item) => isEmptyKeyValue(item)); + } + + if (typeof value === "object") { + if (value.key === "" && value.value === "") return true; + } + + return false; +}