Skip to content

Commit

Permalink
batch updates trigger value
Browse files Browse the repository at this point in the history
  • Loading branch information
vsvamsi1 committed Nov 27, 2024
1 parent 534fd11 commit 9bd05ce
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
3 changes: 2 additions & 1 deletion app/client/src/ce/actions/evaluationActionsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export const EVALUATE_REDUX_ACTIONS = [
// Buffer
ReduxActionTypes.BUFFERED_ACTION,
// Generic
ReduxActionTypes.TRIGGER_EVAL,
// ReduxActionTypes.TRIGGER_EVAL,
ReduxActionTypes.TRIGGER_EVAL_BATCH,
];
// Topics used for datasource and query form evaluations
export const FORM_EVALUATION_REDUX_ACTIONS = [
Expand Down
1 change: 1 addition & 0 deletions app/client/src/ce/constants/ReduxActionConstants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ const EvaluationActionTypes = {
BUFFERED_ACTION: "BUFFERED_ACTION",
CLEAR_CACHE: "CLEAR_CACHE",
TRIGGER_EVAL: "TRIGGER_EVAL",
TRIGGER_EVAL_BATCH: "TRIGGER_EVAL_BATCH",
UPDATE_ACTION_DATA: "UPDATE_ACTION_DATA",
SET_ACTIVE_EDITOR_FIELD: "SET_ACTIVE_EDITOR_FIELD",
RESET_ACTIVE_EDITOR_FIELD: "RESET_ACTIVE_EDITOR_FIELD",
Expand Down
42 changes: 38 additions & 4 deletions app/client/src/sagas/ActionExecution/PluginActionSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,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 @@ -1676,9 +1675,8 @@ function* softRefreshActionsSaga() {
yield put({ type: ReduxActionTypes.SWITCH_ENVIRONMENT_SUCCESS });
}

function* handleUpdateActionData(
action: ReduxAction<updateActionDataPayloadType>,
) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function* handleUpdateActionData(action: any) {
const { actionDataPayload, parentSpan } = action;

yield call(
Expand All @@ -1692,6 +1690,38 @@ function* handleUpdateActionData(
}
}

function* captureActionsWithinPeriodTriggers() {
while (true) {
const buffer = []; // Initialize a new buffer for each batch
const endTime = Date.now() + 10000;
// eslint-disable-next-line prefer-const

while (Date.now() < endTime) {
try {
// Use a non-blocking `take` to capture actions within the period

const { action } = yield race({
action: take(ReduxActionTypes.TRIGGER_EVAL),
del: delay(1000),
});

if (!action) continue;

buffer.push(action);
} catch (e) {
// Handle errors if needed
}
}

// After the time period, dispatch the collected actions
if (buffer.length > 0) {
yield put({
type: ReduxActionTypes.TRIGGER_EVAL_BATCH,
});
}
}
}

// Use a channel to queue all actions

function* captureActionsWithinPeriod() {
Expand Down Expand Up @@ -1745,5 +1775,9 @@ export function* watchPluginActionExecutionSagas() {
takeLatest(ReduxActionTypes.PLUGIN_SOFT_REFRESH, softRefreshActionsSaga),
takeEvery(ReduxActionTypes.EXECUTE_JS_UPDATES, makeUpdateJSCollection),
takeEvery(ReduxActionTypes.START_EVALUATION, captureActionsWithinPeriod),
takeEvery(
ReduxActionTypes.START_EVALUATION,
captureActionsWithinPeriodTriggers,
),
]);
}
8 changes: 4 additions & 4 deletions app/client/src/workers/Evaluation/fns/utils/TriggerEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ const logsHandler = deferredBatchedActionHandler((batchedData) =>

TriggerEmitter.on(BatchKey.process_logs, logsHandler);

const storeUpdatesHandler = priorityBatchedActionHandler((batchedData) =>
WorkerMessenger.ping({
const storeUpdatesHandler = priorityBatchedActionHandler((batchedData) => {
return WorkerMessenger.ping({
method: MAIN_THREAD_ACTION.PROCESS_STORE_UPDATES,
data: batchedData,
}),
);
});
});

TriggerEmitter.on(BatchKey.process_store_updates, storeUpdatesHandler);

Expand Down

0 comments on commit 9bd05ce

Please sign in to comment.