Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions app/client/src/ce/actions/evaluationActionsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const LINT_REDUX_ACTIONS = {
[ReduxActionTypes.INSTALL_LIBRARY_SUCCESS]: true,
[ReduxActionTypes.UNINSTALL_LIBRARY_SUCCESS]: true,
[ReduxActionTypes.BUFFERED_ACTION]: true,
[ReduxActionTypes.BATCH_UPDATES_SUCCESS]: true,
[ReduxActionTypes.BATCH_UPDATES_SUCCESS_CONSOLIDATED]: true,
};

export const LOG_REDUX_ACTIONS = {
Expand Down Expand Up @@ -96,7 +96,8 @@ export const EVALUATE_REDUX_ACTIONS = [
ReduxActionTypes.RESET_WIDGET_META,
ReduxActionTypes.RESET_WIDGET_META_UPDATES,
// Batches
ReduxActionTypes.BATCH_UPDATES_SUCCESS,
// ReduxActionTypes.BATCH_UPDATES_SUCCESS,
ReduxActionTypes.BATCH_UPDATES_SUCCESS_CONSOLIDATED,
// App Theme
ReduxActionTypes.UPDATE_SELECTED_APP_THEME_SUCCESS,
ReduxActionTypes.CHANGE_SELECTED_APP_THEME_SUCCESS,
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 @@ -1085,6 +1085,7 @@ const BatchUpdateActionTypes = {
BATCHED_UPDATE: "BATCHED_UPDATE",
EXECUTE_BATCH: "EXECUTE_BATCH",
BATCH_UPDATES_SUCCESS: "BATCH_UPDATES_SUCCESS",
BATCH_UPDATES_SUCCESS_CONSOLIDATED: "BATCH_UPDATES_SUCCESS_CONSOLIDATED",
};

const HelpActionTypes = {
Expand Down
38 changes: 38 additions & 0 deletions app/client/src/sagas/ActionExecution/PluginActionSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
call,
delay,
put,
race,
select,
take,
takeEvery,
Expand Down Expand Up @@ -1690,6 +1691,39 @@ 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.BATCH_UPDATES_SUCCESS),
del: delay(1000),
});

if (!action) continue;

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

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

export function* watchPluginActionExecutionSagas() {
yield all([
takeLatest(ReduxActionTypes.RUN_ACTION_REQUEST, runActionSaga),
Expand All @@ -1704,5 +1738,9 @@ export function* watchPluginActionExecutionSagas() {
takeLatest(ReduxActionTypes.PLUGIN_SOFT_REFRESH, softRefreshActionsSaga),
takeEvery(ReduxActionTypes.EXECUTE_JS_UPDATES, makeUpdateJSCollection),
takeEvery(ReduxActionTypes.UPDATE_ACTION_DATA, handleUpdateActionData),
takeEvery(
ReduxActionTypes.START_EVALUATION,
captureActionsWithinPeriodTriggers,
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure a single instance of 'captureActionsWithinPeriodTriggers'

Using takeEvery with ReduxActionTypes.START_EVALUATION may start multiple instances of captureActionsWithinPeriodTriggers if START_EVALUATION is dispatched multiple times. To prevent concurrent executions, consider using takeLatest to ensure only one instance runs at a time.

Apply this diff to modify the saga effect:

-    takeEvery(
+    takeLatest(
      ReduxActionTypes.START_EVALUATION,
      captureActionsWithinPeriodTriggers,
    ),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
takeEvery(
ReduxActionTypes.START_EVALUATION,
captureActionsWithinPeriodTriggers,
),
takeLatest(
ReduxActionTypes.START_EVALUATION,
captureActionsWithinPeriodTriggers,
),

]);
}