diff --git a/app/client/src/entities/Engine/AppEditorEngine.ts b/app/client/src/entities/Engine/AppEditorEngine.ts index 803af3e2bc..bbd2d65653 100644 --- a/app/client/src/entities/Engine/AppEditorEngine.ts +++ b/app/client/src/entities/Engine/AppEditorEngine.ts @@ -1,11 +1,11 @@ import { fetchMockDatasources } from "actions/datasourceActions"; import { fetchGitRemoteStatusInit, - fetchBranchesInit, fetchGitProtectedBranchesInit, fetchGitStatusInit, remoteUrlInputValue, resetPullMergeStatus, + fetchBranchesInit, } from "actions/gitSyncActions"; import { restoreRecentEntitiesRequest } from "actions/globalSearchActions"; import { resetEditorSuccess } from "actions/initActions"; @@ -26,7 +26,7 @@ import { } from "@appsmith/constants/ReduxActionConstants"; import { addBranchParam } from "constants/routes"; import type { APP_MODE } from "entities/App"; -import { call, put, select, spawn, take } from "redux-saga/effects"; +import { call, fork, put, select, spawn } from "redux-saga/effects"; import { failFastApiCalls, reportSWStatus, @@ -263,9 +263,6 @@ export default class AppEditorEngine extends AppEngine { public *loadGit(applicationId: string) { const branchInStore: string = yield select(getCurrentGitBranch); - const isGitStatusLiteEnabled: boolean = yield select( - getIsGitStatusLiteEnabled, - ); yield put( restoreRecentEntitiesRequest({ applicationId, @@ -277,17 +274,23 @@ export default class AppEditorEngine extends AppEngine { // add branch query to path and fetch status if (branchInStore) { history.replace(addBranchParam(branchInStore)); + yield fork(this.loadGitInBackground); + } + } - if (isGitStatusLiteEnabled) { - yield put(fetchGitRemoteStatusInit()); - yield put(fetchGitStatusInit({ compareRemote: false })); - } else { - yield put(fetchGitStatusInit({ compareRemote: true })); - } + private *loadGitInBackground() { + const isGitStatusLiteEnabled: boolean = yield select( + getIsGitStatusLiteEnabled, + ); - yield put(fetchBranchesInit()); - yield take(ReduxActionTypes.FETCH_BRANCHES_SUCCESS); - yield put(fetchGitProtectedBranchesInit()); + yield put(fetchBranchesInit()); + yield put(fetchGitProtectedBranchesInit()); + + if (isGitStatusLiteEnabled) { + yield put(fetchGitRemoteStatusInit()); + yield put(fetchGitStatusInit({ compareRemote: false })); + } else { + yield put(fetchGitStatusInit({ compareRemote: true })); } yield put(resetPullMergeStatus()); } diff --git a/app/client/src/sagas/GitSyncSagas.ts b/app/client/src/sagas/GitSyncSagas.ts index df2e59308d..f68b073130 100644 --- a/app/client/src/sagas/GitSyncSagas.ts +++ b/app/client/src/sagas/GitSyncSagas.ts @@ -15,6 +15,7 @@ import { put, select, take, + takeLatest, } from "redux-saga/effects"; import type { TakeableChannel } from "@redux-saga/core"; import type { MergeBranchPayload, MergeStatusPayload } from "api/GitSyncAPI"; @@ -1144,38 +1145,44 @@ function* updateGitProtectedBranchesSaga({ } } -const gitRequestActions: Record< +const gitRequestBlockingActions: Record< (typeof ReduxActionTypes)[keyof typeof ReduxActionTypes], (...args: any[]) => any > = { [ReduxActionTypes.COMMIT_TO_GIT_REPO_INIT]: commitToGitRepoSaga, [ReduxActionTypes.CONNECT_TO_GIT_INIT]: connectToGitSaga, - [ReduxActionTypes.FETCH_GLOBAL_GIT_CONFIG_INIT]: fetchGlobalGitConfig, [ReduxActionTypes.UPDATE_GLOBAL_GIT_CONFIG_INIT]: updateGlobalGitConfig, - [ReduxActionTypes.SWITCH_GIT_BRANCH_INIT]: switchBranch, [ReduxActionTypes.FETCH_BRANCHES_INIT]: fetchBranches, + [ReduxActionTypes.SWITCH_GIT_BRANCH_INIT]: switchBranch, [ReduxActionTypes.CREATE_NEW_BRANCH_INIT]: createNewBranch, - [ReduxActionTypes.FETCH_LOCAL_GIT_CONFIG_INIT]: fetchLocalGitConfig, [ReduxActionTypes.UPDATE_LOCAL_GIT_CONFIG_INIT]: updateLocalGitConfig, - [ReduxActionTypes.FETCH_GIT_STATUS_INIT]: fetchGitStatusSaga, - [ReduxActionTypes.FETCH_GIT_REMOTE_STATUS_INIT]: fetchGitRemoteStatusSaga, [ReduxActionTypes.MERGE_BRANCH_INIT]: mergeBranchSaga, [ReduxActionTypes.FETCH_MERGE_STATUS_INIT]: fetchMergeStatusSaga, [ReduxActionTypes.GIT_PULL_INIT]: gitPullSaga, - [ReduxActionTypes.SHOW_CONNECT_GIT_MODAL]: showConnectGitModal, [ReduxActionTypes.REVOKE_GIT]: disconnectGitSaga, [ReduxActionTypes.IMPORT_APPLICATION_FROM_GIT_INIT]: importAppFromGitSaga, [ReduxActionTypes.GENERATE_SSH_KEY_PAIR_INIT]: generateSSHKeyPairSaga, - [ReduxActionTypes.FETCH_SSH_KEY_PAIR_INIT]: getSSHKeyPairSaga, [ReduxActionTypes.DELETE_BRANCH_INIT]: deleteBranch, [ReduxActionTypes.GIT_DISCARD_CHANGES]: discardChanges, [ReduxActionTypes.GIT_UPDATE_DEFAULT_BRANCH_INIT]: updateGitDefaultBranchSaga, - [ReduxActionTypes.GIT_FETCH_PROTECTED_BRANCHES_INIT]: - fetchGitProtectedBranchesSaga, [ReduxActionTypes.GIT_UPDATE_PROTECTED_BRANCHES_INIT]: updateGitProtectedBranchesSaga, }; +const gitRequestNonBlockingActions: Record< + (typeof ReduxActionTypes)[keyof typeof ReduxActionTypes], + (...args: any[]) => any +> = { + [ReduxActionTypes.FETCH_GLOBAL_GIT_CONFIG_INIT]: fetchGlobalGitConfig, + [ReduxActionTypes.FETCH_LOCAL_GIT_CONFIG_INIT]: fetchLocalGitConfig, + [ReduxActionTypes.FETCH_GIT_STATUS_INIT]: fetchGitStatusSaga, + [ReduxActionTypes.FETCH_GIT_REMOTE_STATUS_INIT]: fetchGitRemoteStatusSaga, + [ReduxActionTypes.SHOW_CONNECT_GIT_MODAL]: showConnectGitModal, + [ReduxActionTypes.FETCH_SSH_KEY_PAIR_INIT]: getSSHKeyPairSaga, + [ReduxActionTypes.GIT_FETCH_PROTECTED_BRANCHES_INIT]: + fetchGitProtectedBranchesSaga, +}; + /** * All git actions on the server are behind a lock, * that means that only one action can be performed at once. @@ -1185,18 +1192,26 @@ const gitRequestActions: Record< * * This will ensure that client is not running parallel requests to the server for git * */ -function* watchGitRequests() { +function* watchGitBlockingRequests() { const gitActionChannel: TakeableChannel = yield actionChannel( - Object.keys(gitRequestActions), + Object.keys(gitRequestBlockingActions), ); while (true) { const { type, ...args }: ReduxAction = yield take(gitActionChannel); - yield call(gitRequestActions[type], { type, ...args }); + yield call(gitRequestBlockingActions[type], { type, ...args }); + } +} + +function* watchGitNonBlockingRequests() { + const keys = Object.keys(gitRequestNonBlockingActions); + for (const actionType of keys) { + yield takeLatest(actionType, gitRequestNonBlockingActions[actionType]); } } export default function* gitSyncSagas() { - yield fork(watchGitRequests); + yield fork(watchGitNonBlockingRequests); + yield fork(watchGitBlockingRequests); }