Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 60 additions & 12 deletions app/client/src/sagas/EvaluationsSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
delay,
fork,
put,
race,
select,
spawn,
take,
Expand Down Expand Up @@ -58,7 +59,7 @@ import {
import type { JSAction, JSCollection } from "entities/JSCollection";
import { getAppMode } from "ee/selectors/applicationSelectors";
import { APP_MODE } from "entities/App";
import { get, isEmpty } from "lodash";
import { get, isEmpty, isEqual } from "lodash";
import type { TriggerMeta } from "ee/sagas/ActionExecution/ActionExecutionSagas";
import { executeActionTriggers } from "ee/sagas/ActionExecution/ActionExecutionSagas";
import {
Expand Down Expand Up @@ -753,24 +754,71 @@ function* evaluationChangeListenerSaga(): any {
EVAL_AND_LINT_REDUX_ACTIONS,
evalQueueBuffer(),
);
let hasTriggerAction = false;

while (true) {
const action: EvaluationReduxAction<unknown | unknown[]> =
yield take(evtActionChannel);
const { action, timeout } = yield race({
action: take(evtActionChannel),
timeout: delay(1000),
});

// 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.
const affectedJSObjects = getAffectedJSObjectIdsFromAction(action);
if (
action?.type === ReduxActionTypes.TRIGGER_EVAL ||
isEqual(action, bufferedAction) ||
isEqual(action, batchUpdateSuccess)
) {
hasTriggerAction = true;
continue;
}

yield call(evalAndLintingHandler, true, action, {
shouldReplay: get(action, "payload.shouldReplay"),
forceEvaluation: shouldForceEval(action),
requiresLogging: shouldLog(action),
affectedJSObjects,
});
if (timeout) {
if (hasTriggerAction) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const action = bufferedAction as any;
const affectedJSObjects = getAffectedJSObjectIdsFromAction(action);

yield call(evalAndLintingHandler, true, action, {
shouldReplay: get(action, "payload.shouldReplay"),
forceEvaluation: shouldForceEval(action),
requiresLogging: shouldLog(action),
affectedJSObjects,
});
}
} else {
// 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.
const affectedJSObjects = getAffectedJSObjectIdsFromAction(action);

yield call(evalAndLintingHandler, true, action, {
shouldReplay: get(action, "payload.shouldReplay"),
forceEvaluation: shouldForceEval(action),
requiresLogging: shouldLog(action),
affectedJSObjects,
});
}

hasTriggerAction = false;
}
}

const bufferedAction = {
postEvalActions: [],
affectedJSObjects: {
isAllAffected: false,
ids: [],
},
type: "BUFFERED_ACTION",
};
const batchUpdateSuccess = {
type: "BATCH_UPDATES_SUCCESS",
payload: [
{
type: "META_UPDATE_DEBOUNCED_EVAL",
payload: {},
},
],
};

// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function* evaluateActionSelectorFieldSaga(action: any) {
Expand Down