@@ -7,31 +7,48 @@ import com.powersync.bucket.LocalOperationCounters
7
7
/* *
8
8
* Information about a progressing download.
9
9
*
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.
12
12
*
13
13
* To obtain a [ProgressWithOperations] instance, use a method on [SyncDownloadProgress] which in turn is available
14
14
* on [SyncStatusData].
15
15
*/
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
+
20
27
/* *
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`.
22
29
*/
23
30
public val fraction: Float get() {
24
- if (completed == 0 ) {
31
+ if (totalOperations == 0 ) {
25
32
return 0.0f
26
33
}
27
34
28
- return completed .toFloat() / total .toFloat()
35
+ return downloadedOperations .toFloat() / totalOperations .toFloat()
29
36
}
30
37
}
31
38
39
+ internal data class ProgressInfo (
40
+ override val downloadedOperations : Int ,
41
+ override val totalOperations : Int ,
42
+ ): ProgressWithOperations
43
+
32
44
/* *
33
45
* Provides realtime progress on how PowerSync is downloading rows.
34
46
*
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
+ *
35
52
* The reported progress always reflects the status towards the end of a sync iteration (after which a consistent
36
53
* snapshot of all buckets is available locally).
37
54
*
@@ -46,7 +63,17 @@ public data class ProgressWithOperations(
46
63
@ConsistentCopyVisibility
47
64
public data class SyncDownloadProgress private constructor(
48
65
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
+
50
77
/* *
51
78
* Creates download progress information from the local progress counters since the last full sync and the target
52
79
* checkpoint.
@@ -69,14 +96,6 @@ public data class SyncDownloadProgress private constructor(
69
96
},
70
97
)
71
98
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
-
80
99
/* *
81
100
* Returns download progress towards all data up until the specified [priority] being received.
82
101
*
@@ -85,7 +104,7 @@ public data class SyncDownloadProgress private constructor(
85
104
*/
86
105
public fun untilPriority (priority : BucketPriority ): ProgressWithOperations {
87
106
val (total, completed) = targetAndCompletedCounts(priority)
88
- return ProgressWithOperations (completed = completed, total = total )
107
+ return ProgressInfo (totalOperations = total, downloadedOperations = completed )
89
108
}
90
109
91
110
internal fun incrementDownloaded (batch : SyncDataBatch ): SyncDownloadProgress =
0 commit comments