Skip to content

Commit 995ae13

Browse files
committed
Fix displaying stats after navigating.
1 parent f72ce5a commit 995ae13

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

tools/diagnostics-app/src/app/views/sync-diagnostics.tsx

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,37 @@ export default function SyncDiagnosticsPage() {
7373
const bucketRowsLoading = bucketRows == null;
7474
const tableRowsLoading = tableRows == null;
7575

76+
const refreshStats = async () => {
77+
// Similar to db.currentState.hasSynced, but synchronized to the onChange events
78+
const hasSynced = await db.getOptional('SELECT 1 FROM ps_buckets WHERE last_applied_op > 0 LIMIT 1');
79+
if (hasSynced != null) {
80+
// These are potentially expensive queries - do not run during initial sync
81+
const bucketRows = await db.getAll(BUCKETS_QUERY);
82+
const tableRows = await db.getAll(TABLES_QUERY);
83+
setBucketRows(bucketRows);
84+
setTableRows(tableRows);
85+
} else {
86+
// Fast query to show progress during initial sync
87+
const bucketRows = await db.getAll(BUCKETS_QUERY_FAST);
88+
setBucketRows(bucketRows);
89+
setTableRows(null);
90+
}
91+
};
92+
7693
React.useEffect(() => {
7794
const controller = new AbortController();
7895

7996
db.onChangeWithCallback(
8097
{
8198
async onChange(event) {
82-
// Similar to db.currentState.hasSynced, but synchronized to the onChange events
83-
const hasSynced = await db.getOptional('SELECT 1 FROM ps_buckets WHERE last_applied_op > 0 LIMIT 1');
84-
if (hasSynced != null) {
85-
// These are potentially expensive queries - do not run during initial sync
86-
const bucketRows = await db.getAll(BUCKETS_QUERY);
87-
const tableRows = await db.getAll(TABLES_QUERY);
88-
setBucketRows(bucketRows);
89-
setTableRows(tableRows);
90-
} else {
91-
// Fast query to show progress during initial sync
92-
const bucketRows = await db.getAll(BUCKETS_QUERY_FAST);
93-
setBucketRows(bucketRows);
94-
setTableRows(null);
95-
}
99+
await refreshStats();
96100
}
97101
},
98102
{ rawTableNames: true, tables: ['ps_oplog', 'ps_buckets', 'ps_data_local__local_bucket_data'], throttleMs: 500 }
99103
);
104+
105+
refreshStats();
106+
100107
return () => {
101108
controller.abort();
102109
};

0 commit comments

Comments
 (0)