Skip to content

Commit 01e890b

Browse files
committed
Record downloaded operations.
1 parent d53fd24 commit 01e890b

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ SELECT
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
5152
FROM local_bucket_data local
@@ -64,6 +65,7 @@ SELECT
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
6971
FROM local_bucket_data local`;
@@ -136,6 +138,7 @@ export default function SyncDiagnosticsPage() {
136138
{ field: 'name', headerName: 'Name', flex: 2 },
137139
{ field: 'tables', headerName: 'Table(s)', flex: 1, type: 'text' },
138140
{ field: 'row_count', headerName: 'Row Count', flex: 1, type: 'number' },
141+
{ field: 'downloaded_operations', headerName: 'Downloaded Operations', flex: 1, type: 'number' },
139142
{ field: 'total_operations', headerName: 'Total Operations', flex: 1, type: 'number' },
140143
{
141144
field: 'data_size',
@@ -172,6 +175,7 @@ export default function SyncDiagnosticsPage() {
172175
name: r.name,
173176
tables: JSON.parse(r.tables ?? '[]').join(', '),
174177
row_count: r.row_count,
178+
downloaded_operations: r.downloaded_operations,
175179
total_operations: r.total_operations,
176180
data_size: r.data_size,
177181
metadata_size: r.metadata_size,
@@ -183,6 +187,7 @@ export default function SyncDiagnosticsPage() {
183187
const totals = {
184188
buckets: rows.length,
185189
row_count: rows.reduce((total, row) => total + row.row_count, 0),
190+
downloaded_operations: rows.reduce((total, row) => total + row.downloaded_operations, 0),
186191
total_operations: rows.reduce((total, row) => total + row.total_operations, 0),
187192
data_size: rows.reduce((total, row) => total + row.data_size, 0),
188193
metadata_size: rows.reduce((total, row) => total + row.metadata_size, 0),
@@ -217,6 +222,7 @@ export default function SyncDiagnosticsPage() {
217222
Number of buckets
218223
</TableCell>
219224
<TableCell component="th">Total Rows</TableCell>
225+
<TableCell component="th">Downloaded Operations</TableCell>
220226
<TableCell component="th">Total Operations</TableCell>
221227
<TableCell component="th">Total Data Size</TableCell>
222228
<TableCell component="th">Total Metadata Size</TableCell>
@@ -226,6 +232,7 @@ export default function SyncDiagnosticsPage() {
226232
<TableRow sx={{ '&:last-child td, &:last-child th': { border: 0 } }}>
227233
<TableCell align="right">{totals.buckets}</TableCell>
228234
<TableCell align="right">{totals.row_count}</TableCell>
235+
<TableCell align="right">{totals.downloaded_operations}</TableCell>
229236
<TableCell align="right">{totals.total_operations}</TableCell>
230237
<TableCell align="right">{formatBytes(totals.data_size)}</TableCell>
231238
<TableCell align="right">{formatBytes(totals.metadata_size)}</TableCell>

tools/diagnostics-app/src/library/powersync/AppSchema.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const local_bucket_data = new Table(
55
total_operations: column.integer,
66
last_op: column.text,
77
download_size: column.integer,
8+
downloaded_operations: column.integer,
89
downloading: column.integer
910
},
1011
{ localOnly: true }

tools/diagnostics-app/src/library/powersync/RecordingStorageAdapter.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ export class RecordingStorageAdapter extends SqliteBucketStorage {
2626
await this.rdb.writeTransaction(async (tx) => {
2727
for (const bucket of checkpoint.buckets) {
2828
await tx.execute(
29-
`INSERT OR REPLACE INTO local_bucket_data(id, total_operations, last_op, download_size, downloading)
29+
`INSERT OR REPLACE INTO local_bucket_data(id, total_operations, last_op, download_size, downloading, downloaded_operations)
3030
VALUES (
3131
?,
3232
?,
3333
IFNULL((SELECT last_op FROM local_bucket_data WHERE id = ?), '0'),
3434
IFNULL((SELECT download_size FROM local_bucket_data WHERE id = ?), 0),
35-
IFNULL((SELECT downloading FROM local_bucket_data WHERE id = ?), TRUE)
35+
IFNULL((SELECT downloading FROM local_bucket_data WHERE id = ?), TRUE),
36+
IFNULL((SELECT downloaded_operations FROM local_bucket_data WHERE id = ?), TRUE)
3637
)`,
37-
[bucket.bucket, bucket.count, bucket.bucket, bucket.bucket, bucket.bucket]
38+
[bucket.bucket, bucket.count, bucket.bucket, bucket.bucket, bucket.bucket, bucket.bucket]
3839
);
3940
}
4041
});
@@ -61,8 +62,13 @@ export class RecordingStorageAdapter extends SqliteBucketStorage {
6162
// Record metrics
6263
const size = JSON.stringify(bucket.data).length;
6364
await tx.execute(
64-
'UPDATE local_bucket_data SET download_size = IFNULL(download_size, 0) + ?, last_op = ?, downloading = ? WHERE id = ?',
65-
[size, bucket.next_after, bucket.has_more, bucket.bucket]
65+
`UPDATE local_bucket_data SET
66+
download_size = IFNULL(download_size, 0) + ?,
67+
last_op = ?,
68+
downloading = ?,
69+
downloaded_operations = IFNULL(downloaded_operations, 0) + ?
70+
WHERE id = ?`,
71+
[size, bucket.next_after, bucket.has_more, bucket.data.length, bucket.bucket]
6672
);
6773
}
6874
});

0 commit comments

Comments
 (0)