mirror of
https://github.com/firstsun-dev/git-files-sync.git
synced 2026-07-22 17:20:30 +00:00
perf(ui): parallelize refresh status checks and throttle re-renders
Refresh checked files one at a time (a sequential network request per file) and re-rendered the whole view after every file, so a large vault was slow. Run the per-file checks with a bounded concurrency pool (8) and re-render on a ~150ms throttle plus a final render. Behavior and results are unchanged; wall time drops roughly in line with the concurrency. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DwioG4CNKUBuKiZdowLFWe
This commit is contained in:
parent
9bcaed65f4
commit
1e21061aa8
1 changed files with 29 additions and 6 deletions
|
|
@ -424,15 +424,38 @@ export class SyncStatusView extends ItemView {
|
|||
});
|
||||
}
|
||||
|
||||
// Checks run with bounded concurrency (each file is an independent network
|
||||
// request) and the view is re-rendered on a throttle rather than once per
|
||||
// file, so a large vault refreshes far faster.
|
||||
private static readonly STATUS_CHECK_CONCURRENCY = 8;
|
||||
private static readonly RENDER_THROTTLE_MS = 150;
|
||||
|
||||
private async performStatusCheck(filesToCheck: Array<TFile | string>): Promise<void> {
|
||||
const total = filesToCheck.length;
|
||||
this.refreshProgress = { current: 0, total };
|
||||
for (let i = 0; i < total; i++) {
|
||||
const file = filesToCheck[i];
|
||||
if (file) await this.refreshFileStatus(file);
|
||||
this.refreshProgress.current = i + 1;
|
||||
this.renderView();
|
||||
}
|
||||
|
||||
let next = 0;
|
||||
let lastRender = 0;
|
||||
const maybeRender = (force = false): void => {
|
||||
const now = Date.now();
|
||||
if (force || now - lastRender >= SyncStatusView.RENDER_THROTTLE_MS) {
|
||||
lastRender = now;
|
||||
this.renderView();
|
||||
}
|
||||
};
|
||||
|
||||
const worker = async (): Promise<void> => {
|
||||
while (next < total) {
|
||||
const file = filesToCheck[next++];
|
||||
if (file) await this.refreshFileStatus(file);
|
||||
this.refreshProgress.current++;
|
||||
maybeRender();
|
||||
}
|
||||
};
|
||||
|
||||
const workerCount = Math.min(SyncStatusView.STATUS_CHECK_CONCURRENCY, total);
|
||||
await Promise.all(Array.from({ length: workerCount }, () => worker()));
|
||||
maybeRender(true);
|
||||
}
|
||||
|
||||
private async refreshFileStatus(fileOrPath: TFile | string): Promise<void> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue