@@ -48,6 +48,8 @@ public final class DataStoreConfiguration {
48
48
static final int DEFAULT_SYNC_PAGE_SIZE = 1_000 ;
49
49
@ VisibleForTesting
50
50
static final boolean DEFAULT_DO_SYNC_RETRY = false ;
51
+ @ VisibleForTesting
52
+ static final int DEFAULT_SYNC_MAX_CONCURRENT_MODELS = 1 ;
51
53
static final int MAX_RECORDS = 1000 ;
52
54
static final long MAX_TIME_SEC = 2 ;
53
55
@@ -58,6 +60,7 @@ public final class DataStoreConfiguration {
58
60
private final Integer syncMaxRecords ;
59
61
private final Integer syncPageSize ;
60
62
private final boolean doSyncRetry ;
63
+ private final Integer syncMaxConcurrentModels ;
61
64
private final Map <String , DataStoreSyncExpression > syncExpressions ;
62
65
private final Long syncIntervalInMinutes ;
63
66
private final Long maxTimeLapseForObserveQuery ;
@@ -71,6 +74,8 @@ private DataStoreConfiguration(Builder builder) {
71
74
this .syncIntervalInMinutes = builder .syncIntervalInMinutes ;
72
75
this .syncExpressions = builder .syncExpressions ;
73
76
this .doSyncRetry = builder .doSyncRetry ;
77
+ this .syncMaxConcurrentModels = builder .syncMaxConcurrentModels != null ?
78
+ builder .syncMaxConcurrentModels : DEFAULT_SYNC_MAX_CONCURRENT_MODELS ;
74
79
this .maxTimeLapseForObserveQuery = builder .maxTimeLapseForObserveQuery ;
75
80
this .observeQueryMaxRecords = builder .observeQueryMaxRecords ;
76
81
}
@@ -126,9 +131,10 @@ public static DataStoreConfiguration defaults() throws DataStoreException {
126
131
.syncInterval (DEFAULT_SYNC_INTERVAL_MINUTES , TimeUnit .MINUTES )
127
132
.syncPageSize (DEFAULT_SYNC_PAGE_SIZE )
128
133
.syncMaxRecords (DEFAULT_SYNC_MAX_RECORDS )
129
- .doSyncRetry (DEFAULT_DO_SYNC_RETRY )
130
- .observeQueryMaxTime (MAX_TIME_SEC )
131
- .observeQueryMaxRecords (MAX_RECORDS )
134
+ .doSyncRetry (DEFAULT_DO_SYNC_RETRY )
135
+ .observeQueryMaxTime (MAX_TIME_SEC )
136
+ .observeQueryMaxRecords (MAX_RECORDS )
137
+ .syncMaxConcurrentModels (DEFAULT_SYNC_MAX_CONCURRENT_MODELS )
132
138
.build ();
133
139
}
134
140
@@ -201,6 +207,23 @@ public Boolean getDoSyncRetry() {
201
207
return this .doSyncRetry ;
202
208
}
203
209
210
+ /**
211
+ * Gets the number of models that are allowed to concurrently sync.
212
+ * NOTE: This value will not be used if any models have associations, instead, the default (1)
213
+ * will be used.
214
+ * Setting this number to a high value requires that the developer ensure app memory is not a
215
+ * concern. If the expected sync data contains a large number of models, with a large number
216
+ * of records per model, the concurrency limit should be set to a conservative value. However,
217
+ * if the expected sync data contains a large number of models, with a small amount of data in
218
+ * each model, setting this limit to a high value will greatly improve sync speeds.
219
+ * @return Limit to the number of models that can sync concurrently
220
+ */
221
+ @ IntRange (from = 1 )
222
+ @ NonNull
223
+ public Integer getSyncMaxConcurrentModels () {
224
+ return syncMaxConcurrentModels ;
225
+ }
226
+
204
227
/**
205
228
* Returns the Map of all {@link DataStoreSyncExpression}s used to filter data received from AppSync, either during
206
229
* a sync or over the real-time subscription.
@@ -247,6 +270,9 @@ public boolean equals(@Nullable Object thatObject) {
247
270
if (!ObjectsCompat .equals (getObserveQueryMaxRecords (), that .getObserveQueryMaxRecords ())) {
248
271
return false ;
249
272
}
273
+ if (!ObjectsCompat .equals (getSyncMaxConcurrentModels (), that .getSyncMaxConcurrentModels ())) {
274
+ return false ;
275
+ }
250
276
return true ;
251
277
}
252
278
@@ -261,6 +287,7 @@ public int hashCode() {
261
287
result = 31 * result + getDoSyncRetry ().hashCode ();
262
288
result = 31 * result + (getObserveQueryMaxRecords () != null ? getObserveQueryMaxRecords ().hashCode () : 0 );
263
289
result = 31 * result + getMaxTimeLapseForObserveQuery ().hashCode ();
290
+ result = 31 * result + getSyncMaxConcurrentModels ().hashCode ();
264
291
return result ;
265
292
}
266
293
@@ -273,9 +300,10 @@ public String toString() {
273
300
", syncPageSize=" + syncPageSize +
274
301
", syncIntervalInMinutes=" + syncIntervalInMinutes +
275
302
", syncExpressions=" + syncExpressions +
276
- ", doSyncRetry=" + doSyncRetry +
277
- ", maxTimeRelapseForObserveQuery=" + maxTimeLapseForObserveQuery +
278
- ", observeQueryMaxRecords=" + observeQueryMaxRecords +
303
+ ", doSyncRetry=" + doSyncRetry +
304
+ ", maxTimeRelapseForObserveQuery=" + maxTimeLapseForObserveQuery +
305
+ ", observeQueryMaxRecords=" + observeQueryMaxRecords +
306
+ ", syncMaxConcurrentModels=" + syncMaxConcurrentModels +
279
307
'}' ;
280
308
}
281
309
@@ -309,6 +337,7 @@ public static final class Builder {
309
337
private Integer syncMaxRecords ;
310
338
private Integer syncPageSize ;
311
339
private boolean doSyncRetry ;
340
+ private Integer syncMaxConcurrentModels ;
312
341
private Map <String , DataStoreSyncExpression > syncExpressions ;
313
342
private boolean ensureDefaults ;
314
343
private JSONObject pluginJson ;
@@ -429,6 +458,24 @@ public Builder syncPageSize(@IntRange(from = 0) Integer syncPageSize) {
429
458
return Builder .this ;
430
459
}
431
460
461
+ /**
462
+ * Sets the max concurrency limit for model syncing. Default is 1
463
+ * NOTE: If any sync models have associations, this value will be unused and the default (1)
464
+ * will be used.
465
+ * Setting this number to a high value requires that the developer ensure app memory is not a
466
+ * concern. If the expected sync data contains a large number of models, with a large number
467
+ * of records per model, the concurrency limit should be set to a conservative value. However,
468
+ * if the expected sync data contains a large number of models, with a small amount of data in
469
+ * each model, setting this limit to a high value will greatly improve sync speeds.
470
+ * @param syncMaxConcurrentModels Number of models that can sync concurrently
471
+ * @return Current builder
472
+ */
473
+ @ NonNull
474
+ public Builder syncMaxConcurrentModels (@ IntRange (from = 1 ) Integer syncMaxConcurrentModels ) {
475
+ this .syncMaxConcurrentModels = syncMaxConcurrentModels ;
476
+ return Builder .this ;
477
+ }
478
+
432
479
/**
433
480
* Sets a sync expression for a particular model to filter which data is synced locally.
434
481
* The expression is evaluated each time DataStore is started.
@@ -518,6 +565,10 @@ private void applyUserProvidedConfiguration() {
518
565
syncPageSize = getValueOrDefault (userProvidedConfiguration .getSyncPageSize (), syncPageSize );
519
566
syncExpressions = userProvidedConfiguration .getSyncExpressions ();
520
567
doSyncRetry = getValueOrDefault (userProvidedConfiguration .getDoSyncRetry (), doSyncRetry );
568
+ syncMaxConcurrentModels = getValueOrDefault (
569
+ userProvidedConfiguration .getSyncMaxConcurrentModels (),
570
+ syncMaxConcurrentModels
571
+ );
521
572
observeQueryMaxRecords = getValueOrDefault (userProvidedConfiguration .getObserveQueryMaxRecords (),
522
573
observeQueryMaxRecords );
523
574
maxTimeLapseForObserveQuery = userProvidedConfiguration .getMaxTimeLapseForObserveQuery ()
@@ -548,6 +599,10 @@ public DataStoreConfiguration build() throws DataStoreException {
548
599
syncIntervalInMinutes = getValueOrDefault (syncIntervalInMinutes , DEFAULT_SYNC_INTERVAL_MINUTES );
549
600
syncMaxRecords = getValueOrDefault (syncMaxRecords , DEFAULT_SYNC_MAX_RECORDS );
550
601
syncPageSize = getValueOrDefault (syncPageSize , DEFAULT_SYNC_PAGE_SIZE );
602
+ syncMaxConcurrentModels = getValueOrDefault (
603
+ syncMaxConcurrentModels ,
604
+ DEFAULT_SYNC_MAX_CONCURRENT_MODELS
605
+ );
551
606
observeQueryMaxRecords = getValueOrDefault (observeQueryMaxRecords , MAX_RECORDS );
552
607
maxTimeLapseForObserveQuery = maxTimeLapseForObserveQuery == 0 ? MAX_TIME_SEC :
553
608
maxTimeLapseForObserveQuery ;
0 commit comments