Skip to content

Commit

Permalink
batching handleActionUpdates
Browse files Browse the repository at this point in the history
  • Loading branch information
vsvamsi1 committed Dec 19, 2024
1 parent e22dbd1 commit 1878641
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
20 changes: 0 additions & 20 deletions app/client/src/sagas/ActionExecution/PluginActionSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
takeLatest,
} from "redux-saga/effects";
import * as Sentry from "@sentry/react";
import type { updateActionDataPayloadType } from "actions/pluginActionActions";
import {
clearActionResponse,
executePageLoadActions,
Expand Down Expand Up @@ -104,7 +103,6 @@ import { EMPTY_RESPONSE } from "components/editorComponents/emptyResponse";
import type { AppState } from "ee/reducers";
import { DEFAULT_EXECUTE_ACTION_TIMEOUT_MS } from "ee/constants/ApiConstants";
import { evaluateActionBindings } from "sagas/EvaluationsSaga";
import { evalWorker } from "utils/workerInstances";
import { isBlobUrl, parseBlobUrl } from "utils/AppsmithUtils";
import { getType, Types } from "utils/TypeHelpers";
import { matchPath } from "react-router";
Expand Down Expand Up @@ -152,7 +150,6 @@ import {
getCurrentEnvironmentDetails,
getCurrentEnvironmentName,
} from "ee/selectors/environmentSelectors";
import { EVAL_WORKER_ACTIONS } from "ee/workers/Evaluation/evalWorkerActions";
import { getIsActionCreatedInApp } from "ee/utils/getIsActionCreatedInApp";
import type { OtlpSpan } from "UITelemetry/generateTraces";
import {
Expand Down Expand Up @@ -1656,22 +1653,6 @@ function* softRefreshActionsSaga() {
yield put({ type: ReduxActionTypes.SWITCH_ENVIRONMENT_SUCCESS });
}

function* handleUpdateActionData(
action: ReduxAction<updateActionDataPayloadType>,
) {
const { actionDataPayload, parentSpan } = action.payload;

yield call(
evalWorker.request,
EVAL_WORKER_ACTIONS.UPDATE_ACTION_DATA,
actionDataPayload,
);

if (parentSpan) {
endSpan(parentSpan);
}
}

export function* watchPluginActionExecutionSagas() {
yield all([
takeLatest(ReduxActionTypes.RUN_ACTION_REQUEST, runActionSaga),
Expand All @@ -1685,6 +1666,5 @@ export function* watchPluginActionExecutionSagas() {
),
takeLatest(ReduxActionTypes.PLUGIN_SOFT_REFRESH, softRefreshActionsSaga),
takeEvery(ReduxActionTypes.EXECUTE_JS_UPDATES, makeUpdateJSCollection),
takeEvery(ReduxActionTypes.UPDATE_ACTION_DATA, handleUpdateActionData),
]);
}
38 changes: 33 additions & 5 deletions app/client/src/sagas/EvaluationsSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,18 +542,23 @@ export function evalQueueBuffer() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let collectedPostEvalActions: any = [];
let collectedAffectedJSObjects: AffectedJSObjects = defaultAffectedJSObjects;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let collectedHandleUpdates: any = [];

const take = () => {
if (canTake) {
const resp = collectedPostEvalActions;
const respCollectedHandleUpdates = collectedHandleUpdates;

collectedHandleUpdates = [];
collectedPostEvalActions = [];
const affectedJSObjects = collectedAffectedJSObjects;

collectedAffectedJSObjects = defaultAffectedJSObjects;
canTake = false;

return {
actionDataPayload: respCollectedHandleUpdates,
postEvalActions: resp,
affectedJSObjects,
type: ReduxActionTypes.BUFFERED_ACTION,
Expand All @@ -568,11 +573,24 @@ export function evalQueueBuffer() {
return [];
};

const put = (action: EvaluationReduxAction<unknown | unknown[]>) => {
if (!shouldProcessAction(action)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const put = (action: EvaluationReduxAction<any>) => {
if (
!shouldProcessAction(action) &&
action.type !== ReduxActionTypes.UPDATE_ACTION_DATA
) {
return;
}

const { actionDataPayload } = action.payload;

if (
action.type === ReduxActionTypes.UPDATE_ACTION_DATA &&
actionDataPayload.length
) {
collectedHandleUpdates.push(...actionDataPayload);
}

canTake = true;
// extract the affected JS action ids from the action and pass them
// as a part of the buffered action
Expand Down Expand Up @@ -750,13 +768,23 @@ function* evaluationChangeListenerSaga(): any {
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const evtActionChannel: ActionPattern<Action<any>> = yield actionChannel(
EVAL_AND_LINT_REDUX_ACTIONS,
[...EVAL_AND_LINT_REDUX_ACTIONS, ReduxActionTypes.UPDATE_ACTION_DATA],
evalQueueBuffer(),
);

while (true) {
const action: EvaluationReduxAction<unknown | unknown[]> =
yield take(evtActionChannel);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const action: any = yield take(evtActionChannel);

if (action?.actionDataPayload?.length) {
yield call(
evalWorker.request,
EVAL_WORKER_ACTIONS.UPDATE_ACTION_DATA,
action.actionDataPayload,
);
}

yield delay(500);

// We are dequing actions from the buffer and inferring the JS actions affected by each
// action. Through this we know ahead the nodes we need to specifically diff, thereby improving performance.
Expand Down

0 comments on commit 1878641

Please sign in to comment.