git ssb

1+

Daan Patchwork / manyverse



Commit b010d069a996cc4607a7951dd7ede6898688f52a

dx: improve drawer progress estimate calculation

Andre Staltz committed on 3/5/2021, 10:31:23 AM
Parent: 3edce198aabd29880218a253eae3c4c70be2d33f

Files changed

src/frontend/screens/drawer/model.tschanged
src/frontend/screens/drawer/model.tsView
@@ -15,8 +15,9 @@
1515 indexingProgress: number;
1616 combinedProgress: number;
1717 checkpointCombinedProgress: number;
1818 checkpoint: number;
19+ recentEstimates: Array<number>;
1920 estimateProgressDone: number;
2021 canPublishSSB: boolean;
2122 selfAvatarUrl?: string;
2223 name?: string;
@@ -44,8 +45,9 @@
4445 indexingProgress: 0,
4546 combinedProgress: 0,
4647 checkpointCombinedProgress: 0,
4748 checkpoint: Date.now(),
49+ recentEstimates: [],
4850 estimateProgressDone: 0,
4951 canPublishSSB: true,
5052 };
5153 } else {
@@ -72,8 +74,9 @@
7274 migrationProgress: 0,
7375 indexingProgress: 0,
7476 combinedProgress: 0,
7577 checkpointCombinedProgress: 0,
78+ recentEstimates: [],
7679 estimateProgressDone: 0,
7780 checkpoint: Date.now(),
7881 canPublishSSB: true,
7982 };
@@ -90,16 +93,22 @@
9093 function updateEstimateProgressDone_mutating(state: State) {
9194 const now = Date.now();
9295 if (state.combinedProgress <= 0 || state.combinedProgress >= 1) {
9396 state.estimateProgressDone = 0;
97+ state.recentEstimates = [];
9498 state.checkpoint = now;
9599 } else if (state.checkpoint + CHECKPOINT_INTERVAL < now) {
96100 const rateOfProgress =
97101 (state.combinedProgress - state.checkpointCombinedProgress) /
98102 (now - state.checkpoint);
99103 const remaining = 1 - state.combinedProgress;
100104 if (state.combinedProgress > state.checkpointCombinedProgress) {
101- state.estimateProgressDone = remaining / rateOfProgress;
105+ // Calculate a moving average of the last 6 estimates
106+ state.recentEstimates.push(remaining / rateOfProgress);
107+ if (state.recentEstimates.length > 3) state.recentEstimates.shift();
108+ state.estimateProgressDone =
109+ state.recentEstimates.reduce((acc, x) => acc + x, 0) /
110+ state.recentEstimates.length;
102111 }
103112 state.checkpointCombinedProgress = state.combinedProgress;
104113 state.checkpoint = now;
105114 }

Built with git-ssb-web