@@ -7,31 +7,48 @@ import com.powersync.bucket.LocalOperationCounters
77/* *
88 * Information about a progressing download.
99 *
10- * This reports the [total ] amount of operations to download, how many of them have already been [completed] and finally
11- * a [fraction] indicating relative progress.
10+ * This reports the [totalOperations ] amount of operations to download, how many of them have already been
11+ * [downloadedOperations] and finally a [fraction] indicating relative progress.
1212 *
1313 * To obtain a [ProgressWithOperations] instance, use a method on [SyncDownloadProgress] which in turn is available
1414 * on [SyncStatusData].
1515 */
16- public data class ProgressWithOperations (
17- val completed : Int ,
18- val total : Int ,
19- ) {
16+ public interface ProgressWithOperations {
17+ /* *
18+ * How many operations need to be downloaded in total for the current download to complete.
19+ */
20+ public val totalOperations: Int
21+
22+ /* *
23+ * How many operations, out of [totalOperations], have already been downloaded.
24+ */
25+ public val downloadedOperations: Int
26+
2027 /* *
21- * The relative amount of [total] items that have been [completed ], as a number between `0.0` and `1.0`.
28+ * The relative amount of [totalOperations] to items in [downloadedOperations ], as a number between `0.0` and `1.0`.
2229 */
2330 public val fraction: Float get() {
24- if (completed == 0 ) {
31+ if (totalOperations == 0 ) {
2532 return 0.0f
2633 }
2734
28- return completed .toFloat() / total .toFloat()
35+ return downloadedOperations .toFloat() / totalOperations .toFloat()
2936 }
3037}
3138
39+ internal data class ProgressInfo (
40+ override val downloadedOperations : Int ,
41+ override val totalOperations : Int ,
42+ ): ProgressWithOperations
43+
3244/* *
3345 * Provides realtime progress on how PowerSync is downloading rows.
3446 *
47+ * This type reports progress by implementing [ProgressWithOperations], meaning that the [totalOperations],
48+ * [downloadedOperations] and [fraction] getters are available on this instance.
49+ * Additionally, it's possible to obtain the progress towards a specific priority only (instead of tracking progress for
50+ * the entire download) by using [untilPriority].
51+ *
3552 * The reported progress always reflects the status towards the end of a sync iteration (after which a consistent
3653 * snapshot of all buckets is available locally).
3754 *
@@ -46,7 +63,17 @@ public data class ProgressWithOperations(
4663@ConsistentCopyVisibility
4764public data class SyncDownloadProgress private constructor(
4865 private val buckets : Map <String , BucketProgress >,
49- ) {
66+ ): ProgressWithOperations {
67+
68+ override val downloadedOperations: Int
69+ override val totalOperations: Int
70+
71+ init {
72+ val (target, completed) = targetAndCompletedCounts(BucketPriority .FULL_SYNC_PRIORITY )
73+ totalOperations = target
74+ downloadedOperations = completed
75+ }
76+
5077 /* *
5178 * Creates download progress information from the local progress counters since the last full sync and the target
5279 * checkpoint.
@@ -69,14 +96,6 @@ public data class SyncDownloadProgress private constructor(
6996 },
7097 )
7198
72- /* *
73- * Download progress towards a complete checkpoint being received.
74- *
75- * The returned [ProgressWithOperations] instance tracks the target amount of operations that need to be downloaded
76- * in total and how many of them have already been received.
77- */
78- public val untilCompletion: ProgressWithOperations get() = untilPriority(BucketPriority .FULL_SYNC_PRIORITY )
79-
8099 /* *
81100 * Returns download progress towards all data up until the specified [priority] being received.
82101 *
@@ -85,7 +104,7 @@ public data class SyncDownloadProgress private constructor(
85104 */
86105 public fun untilPriority (priority : BucketPriority ): ProgressWithOperations {
87106 val (total, completed) = targetAndCompletedCounts(priority)
88- return ProgressWithOperations (completed = completed, total = total )
107+ return ProgressInfo (totalOperations = total, downloadedOperations = completed )
89108 }
90109
91110 internal fun incrementDownloaded (batch : SyncDataBatch ): SyncDownloadProgress =
0 commit comments