Skip to content

Commit 56f3e3d

Browse files
committed
Added GetUploadQueueStats.
1 parent e8de1f2 commit 56f3e3d

File tree

2 files changed

+477
-416
lines changed

2 files changed

+477
-416
lines changed

PowerSync/PowerSync.Common/Client/PowerSyncDatabase.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,49 @@ await Database.WriteTransaction(async tx =>
419419
Database.Close();
420420
Closed = true;
421421
}
422+
/**
423+
* Get upload queue size estimate and count.
424+
*/
425+
// async getUploadQueueStats(includeSize?: boolean): Promise<UploadQueueStats> {
426+
// return this.readTransaction(async (tx) => {
427+
// if (includeSize) {
428+
// const result = await tx.execute(
429+
// `SELECT SUM(cast(data as blob) + 20) as size, count(*) as count FROM ${PSInternalTable.CRUD}`
430+
// );
431+
432+
// const row = result.rows!.item(0);
433+
// return new UploadQueueStats(row?.count ?? 0, row?.size ?? 0);
434+
// } else {
435+
// const result = await tx.execute(`SELECT count(*) as count FROM ${PSInternalTable.CRUD}`);
436+
// const row = result.rows!.item(0);
437+
// return new UploadQueueStats(row?.count ?? 0);
438+
// }
439+
// });
440+
// }
441+
442+
private record UploadQueueStatsResult(int size, int count);
443+
/// <summary>
444+
/// Get upload queue size estimate and count.
445+
/// </summary>
446+
public async Task<UploadQueueStats> GetUploadQueueStats(bool includeSize = false)
447+
{
448+
if (includeSize)
449+
{
450+
var result = await Database.Get<UploadQueueStatsResult>(
451+
$"SELECT SUM(cast(data as blob) + 20) as size, count(*) as count FROM {PSInternalTable.CRUD}"
452+
);
453+
454+
return new UploadQueueStats(result.count, result.size);
455+
}
456+
else
457+
{
458+
var result = await Database.Get<UploadQueueStatsResult>(
459+
$"SELECT count(*) as count FROM {PSInternalTable.CRUD}"
460+
);
461+
return new UploadQueueStats(result.count);
462+
}
463+
}
464+
422465

423466
/// <summary>
424467
/// Get a batch of crud data to upload.

0 commit comments

Comments
 (0)