* Execute an actual refresh.
(
repositoryPath: string,
layers: GitStateLayer[],
force: boolean,
reason: RefreshReason,
silent: boolean,
source?: string
)
| 369 | * Execute an actual refresh. |
| 370 | */ |
| 371 | private async doRefresh( |
| 372 | repositoryPath: string, |
| 373 | layers: GitStateLayer[], |
| 374 | force: boolean, |
| 375 | reason: RefreshReason, |
| 376 | silent: boolean, |
| 377 | source?: string |
| 378 | ): Promise<void> { |
| 379 | const existingLock = this.refreshLocks.get(repositoryPath); |
| 380 | if (existingLock) { |
| 381 | if (!force) { |
| 382 | await existingLock; |
| 383 | return; |
| 384 | } |
| 385 | try { |
| 386 | await existingLock; |
| 387 | } catch { |
| 388 | // A force refresh after a failed in-flight refresh should still get a |
| 389 | // chance to rebuild fresh state. |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | const startedAt = nowMs(); |
| 394 | const shouldProbeReason = |
| 395 | reason === 'window-focus' || reason === 'visibility' || reason === 'mount'; |
| 396 | let probeError: string | null = null; |
| 397 | let probeOutcome = 'completed'; |
| 398 | |
| 399 | let state = this.getOrCreateState(repositoryPath); |
| 400 | const prevState = { ...state }; |
| 401 | |
| 402 | |
| 403 | const now = Date.now(); |
| 404 | const layersToRefresh = force |
| 405 | ? layers |
| 406 | : layers.filter((layer) => this.isCacheExpired(state, layer, now)); |
| 407 | |
| 408 | if (layersToRefresh.length === 0) { |
| 409 | if (shouldProbeReason) { |
| 410 | sendDebugProbe('GitStateManager.ts:doRefresh', 'Git refresh skipped by cache', { |
| 411 | repositoryPath, |
| 412 | reason, |
| 413 | force, |
| 414 | silent, |
| 415 | requestedLayers: layers, |
| 416 | }); |
| 417 | } |
| 418 | return; |
| 419 | } |
| 420 | |
| 421 | log.debug('Starting refresh', { repositoryPath, layersToRefresh, reason }); |
| 422 | |
| 423 | const refreshPromise = (async () => { |
| 424 | try { |
| 425 | |
| 426 | if (!silent) { |
| 427 | state = this.updateState(repositoryPath, { |
| 428 | isRefreshing: true, |
no test coverage detected