11import { NavigationPage } from '@/components/navigation/NavigationPage' ;
2- import { clearData , db , syncErrorTracker } from '@/library/powersync/ConnectionManager' ;
2+ import { clearData , db , sync , syncErrorTracker } from '@/library/powersync/ConnectionManager' ;
33import {
44 Box ,
55 Button ,
4646 stats.metadata_size,
4747 IFNULL(stats.row_count, 0) as row_count,
4848 local.download_size,
49+ local.downloaded_operations,
4950 local.total_operations,
5051 local.downloading
5152FROM local_bucket_data local
6465 0 as metadata_size,
6566 0 as row_count,
6667 local.download_size,
68+ local.downloaded_operations,
6769 local.total_operations,
6870 local.downloading
6971FROM local_bucket_data local` ;
@@ -81,14 +83,23 @@ export default function SyncDiagnosticsPage() {
8183 // Similar to db.currentState.hasSynced, but synchronized to the onChange events
8284 const { synced_at } = await db . get < { synced_at : string | null } > ( 'SELECT powersync_last_synced_at() as synced_at' ) ;
8385 setlastSyncedAt ( synced_at ? new Date ( synced_at + 'Z' ) : null ) ;
84- if ( synced_at != null ) {
86+ if ( synced_at != null && ! sync . syncStatus . dataFlowStatus . downloading ) {
8587 // These are potentially expensive queries - do not run during initial sync
8688 const bucketRows = await db . getAll ( BUCKETS_QUERY ) ;
8789 const tableRows = await db . getAll ( TABLES_QUERY ) ;
8890 setBucketRows ( bucketRows ) ;
8991 setTableRows ( tableRows ) ;
92+ } else if ( synced_at != null ) {
93+ // Busy downloading, but have already synced once
94+ const bucketRows = await db . getAll ( BUCKETS_QUERY_FAST ) ;
95+ setBucketRows ( bucketRows ) ;
96+ // Load tables if we haven't yet
97+ if ( tableRows == null ) {
98+ const tableRows = await db . getAll ( TABLES_QUERY ) ;
99+ setTableRows ( tableRows ) ;
100+ }
90101 } else {
91- // Fast query to show progress during initial sync
102+ // Fast query to show progress during initial sync / while downloading bulk data
92103 const bucketRows = await db . getAll ( BUCKETS_QUERY_FAST ) ;
93104 setBucketRows ( bucketRows ) ;
94105 setTableRows ( null ) ;
@@ -127,6 +138,7 @@ export default function SyncDiagnosticsPage() {
127138 { field : 'name' , headerName : 'Name' , flex : 2 } ,
128139 { field : 'tables' , headerName : 'Table(s)' , flex : 1 , type : 'text' } ,
129140 { field : 'row_count' , headerName : 'Row Count' , flex : 1 , type : 'number' } ,
141+ { field : 'downloaded_operations' , headerName : 'Downloaded Operations' , flex : 1 , type : 'number' } ,
130142 { field : 'total_operations' , headerName : 'Total Operations' , flex : 1 , type : 'number' } ,
131143 {
132144 field : 'data_size' ,
@@ -163,6 +175,7 @@ export default function SyncDiagnosticsPage() {
163175 name : r . name ,
164176 tables : JSON . parse ( r . tables ?? '[]' ) . join ( ', ' ) ,
165177 row_count : r . row_count ,
178+ downloaded_operations : r . downloaded_operations ,
166179 total_operations : r . total_operations ,
167180 data_size : r . data_size ,
168181 metadata_size : r . metadata_size ,
@@ -174,6 +187,7 @@ export default function SyncDiagnosticsPage() {
174187 const totals = {
175188 buckets : rows . length ,
176189 row_count : rows . reduce ( ( total , row ) => total + row . row_count , 0 ) ,
190+ downloaded_operations : rows . reduce ( ( total , row ) => total + row . downloaded_operations , 0 ) ,
177191 total_operations : rows . reduce ( ( total , row ) => total + row . total_operations , 0 ) ,
178192 data_size : rows . reduce ( ( total , row ) => total + row . data_size , 0 ) ,
179193 metadata_size : rows . reduce ( ( total , row ) => total + row . metadata_size , 0 ) ,
@@ -208,6 +222,7 @@ export default function SyncDiagnosticsPage() {
208222 Number of buckets
209223 </ TableCell >
210224 < TableCell component = "th" > Total Rows</ TableCell >
225+ < TableCell component = "th" > Downloaded Operations</ TableCell >
211226 < TableCell component = "th" > Total Operations</ TableCell >
212227 < TableCell component = "th" > Total Data Size</ TableCell >
213228 < TableCell component = "th" > Total Metadata Size</ TableCell >
@@ -217,6 +232,7 @@ export default function SyncDiagnosticsPage() {
217232 < TableRow sx = { { '&:last-child td, &:last-child th' : { border : 0 } } } >
218233 < TableCell align = "right" > { totals . buckets } </ TableCell >
219234 < TableCell align = "right" > { totals . row_count } </ TableCell >
235+ < TableCell align = "right" > { totals . downloaded_operations } </ TableCell >
220236 < TableCell align = "right" > { totals . total_operations } </ TableCell >
221237 < TableCell align = "right" > { formatBytes ( totals . data_size ) } </ TableCell >
222238 < TableCell align = "right" > { formatBytes ( totals . metadata_size ) } </ TableCell >
0 commit comments