Skip to content

Commit aa589f3

Browse files
committed
refactor(sync progress): enhance progress estimation for providers without known total
1 parent 54700c1 commit aa589f3

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

apps/web/src/components/dashboard/sync-progress/sync-progress-overlay.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,20 @@ const calculateOverallProgress = (data: SyncProgress) => {
1919

2020
if (provider.stage === "done") {
2121
providerPercent = 100;
22-
} else if (provider.stage === "fetching" && provider.current !== null) {
22+
} else if (provider.current !== null) {
2323
if (provider.total !== null && provider.total > 0) {
2424
// Use precise current/total for fetching progress (Fitbit-style with known total)
2525
providerPercent = Math.round((provider.current / provider.total) * 100);
2626
} else {
27-
// For providers without known total (Withings), estimate based on current page
28-
// First page = 20%, subsequent pages add diminishing returns
29-
providerPercent = Math.min(20 + provider.current * 15, 80);
27+
const current = Math.max(provider.current, 1);
28+
// For providers without known total (Withings), use diminishing returns that approaches 99% but never reaches it.
29+
// Anchors at 20% for the first page and asymptotically approaches 99%.
30+
const start = 20; // percent at page 1
31+
const asymptote = 99; // never reached
32+
const decay = 0.95; // 0 < decay < 1, higher = slower approach
33+
const estimated = asymptote - (asymptote - start) * Math.pow(decay, current - 1);
34+
providerPercent = Math.floor(estimated); // floor ensures we never hit 99
3035
}
31-
} else if (provider.stage === "init") {
32-
providerPercent = 5;
33-
} else if (provider.stage === "fetching") {
34-
providerPercent = 10; // fallback if no current/total
35-
} else if (provider.stage === "merging") {
36-
providerPercent = 90;
3736
}
3837

3938
return total + providerPercent;

0 commit comments

Comments
 (0)