feat(git): make fetch command asynchronous for improved performance
The fetch command has been updated to run asynchronously, allowing for better performance and responsiveness in the application. This change ensures that the command does not block the main thread, enhancing the user experience when interacting with repositories. - Fetch command now uses async/await for non-blocking execution - Added a grace period to prevent immediate background fetch after switching repositories - Improved handling of authentication errors during fetch operations
This commit is contained in:
+4
-4
@@ -189,8 +189,10 @@
|
||||
const AUTO_REFRESH_INTERVAL = 4000;
|
||||
let autoRefreshTimer: ReturnType<typeof setInterval> | undefined;
|
||||
const BACKGROUND_FETCH_INTERVAL = 180_000;
|
||||
const BACKGROUND_FETCH_AFTER_SWITCH_GRACE_MS = 30_000;
|
||||
let backgroundFetchTimer: ReturnType<typeof setInterval> | undefined;
|
||||
let backgroundFetchInFlight = false;
|
||||
let lastRepoSwitchAt = 0;
|
||||
let updateToastOpen = false;
|
||||
let updateToastState: UpdateToastState = "available";
|
||||
let pendingUpdate: Update | null = null;
|
||||
@@ -264,6 +266,7 @@
|
||||
// Push buttons instead, not as a background popup.
|
||||
async function backgroundFetchTick() {
|
||||
if (!autoRefreshEnabled || activeView !== "repository" || !activeRepoPath || isBusy || backgroundFetchInFlight) return;
|
||||
if (Date.now() - lastRepoSwitchAt < BACKGROUND_FETCH_AFTER_SWITCH_GRACE_MS) return;
|
||||
backgroundFetchInFlight = true;
|
||||
try {
|
||||
await fetchRemote(activeRepoPath);
|
||||
@@ -869,11 +872,8 @@
|
||||
await refreshBranchList(activeRepoPath, bundle.branches);
|
||||
await refreshCommitHistory(activeRepoPath, bundle.commits);
|
||||
await refreshExplorerFiles(activeRepoPath, bundle.files);
|
||||
lastRepoSwitchAt = Date.now();
|
||||
});
|
||||
// Silent background fetch on open, same as the periodic tick — no "Fetching" indicator,
|
||||
// just brings ahead/behind (and the taskbar badge) up to date without blocking the
|
||||
// repo-open flow.
|
||||
void backgroundFetchTick();
|
||||
}
|
||||
|
||||
async function chooseRepositoryFolder() {
|
||||
|
||||
Reference in New Issue
Block a user