@@ -48,6 +48,8 @@ public final class DataStoreConfiguration {
4848 static final int DEFAULT_SYNC_PAGE_SIZE = 1_000 ;
4949 @ VisibleForTesting
5050 static final boolean DEFAULT_DO_SYNC_RETRY = false ;
51+ @ VisibleForTesting
52+ static final int DEFAULT_SYNC_MAX_CONCURRENT_MODELS = 1 ;
5153 static final int MAX_RECORDS = 1000 ;
5254 static final long MAX_TIME_SEC = 2 ;
5355
@@ -58,6 +60,7 @@ public final class DataStoreConfiguration {
5860 private final Integer syncMaxRecords ;
5961 private final Integer syncPageSize ;
6062 private final boolean doSyncRetry ;
63+ private final Integer syncMaxConcurrentModels ;
6164 private final Map <String , DataStoreSyncExpression > syncExpressions ;
6265 private final Long syncIntervalInMinutes ;
6366 private final Long maxTimeLapseForObserveQuery ;
@@ -71,6 +74,8 @@ private DataStoreConfiguration(Builder builder) {
7174 this .syncIntervalInMinutes = builder .syncIntervalInMinutes ;
7275 this .syncExpressions = builder .syncExpressions ;
7376 this .doSyncRetry = builder .doSyncRetry ;
77+ this .syncMaxConcurrentModels = builder .syncMaxConcurrentModels != null ?
78+ builder .syncMaxConcurrentModels : DEFAULT_SYNC_MAX_CONCURRENT_MODELS ;
7479 this .maxTimeLapseForObserveQuery = builder .maxTimeLapseForObserveQuery ;
7580 this .observeQueryMaxRecords = builder .observeQueryMaxRecords ;
7681 }
@@ -126,9 +131,10 @@ public static DataStoreConfiguration defaults() throws DataStoreException {
126131 .syncInterval (DEFAULT_SYNC_INTERVAL_MINUTES , TimeUnit .MINUTES )
127132 .syncPageSize (DEFAULT_SYNC_PAGE_SIZE )
128133 .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 )
132138 .build ();
133139 }
134140
@@ -201,6 +207,23 @@ public Boolean getDoSyncRetry() {
201207 return this .doSyncRetry ;
202208 }
203209
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+
204227 /**
205228 * Returns the Map of all {@link DataStoreSyncExpression}s used to filter data received from AppSync, either during
206229 * a sync or over the real-time subscription.
@@ -247,6 +270,9 @@ public boolean equals(@Nullable Object thatObject) {
247270 if (!ObjectsCompat .equals (getObserveQueryMaxRecords (), that .getObserveQueryMaxRecords ())) {
248271 return false ;
249272 }
273+ if (!ObjectsCompat .equals (getSyncMaxConcurrentModels (), that .getSyncMaxConcurrentModels ())) {
274+ return false ;
275+ }
250276 return true ;
251277 }
252278
@@ -261,6 +287,7 @@ public int hashCode() {
261287 result = 31 * result + getDoSyncRetry ().hashCode ();
262288 result = 31 * result + (getObserveQueryMaxRecords () != null ? getObserveQueryMaxRecords ().hashCode () : 0 );
263289 result = 31 * result + getMaxTimeLapseForObserveQuery ().hashCode ();
290+ result = 31 * result + getSyncMaxConcurrentModels ().hashCode ();
264291 return result ;
265292 }
266293
@@ -273,9 +300,10 @@ public String toString() {
273300 ", syncPageSize=" + syncPageSize +
274301 ", syncIntervalInMinutes=" + syncIntervalInMinutes +
275302 ", syncExpressions=" + syncExpressions +
276- ", doSyncRetry=" + doSyncRetry +
277- ", maxTimeRelapseForObserveQuery=" + maxTimeLapseForObserveQuery +
278- ", observeQueryMaxRecords=" + observeQueryMaxRecords +
303+ ", doSyncRetry=" + doSyncRetry +
304+ ", maxTimeRelapseForObserveQuery=" + maxTimeLapseForObserveQuery +
305+ ", observeQueryMaxRecords=" + observeQueryMaxRecords +
306+ ", syncMaxConcurrentModels=" + syncMaxConcurrentModels +
279307 '}' ;
280308 }
281309
@@ -309,6 +337,7 @@ public static final class Builder {
309337 private Integer syncMaxRecords ;
310338 private Integer syncPageSize ;
311339 private boolean doSyncRetry ;
340+ private Integer syncMaxConcurrentModels ;
312341 private Map <String , DataStoreSyncExpression > syncExpressions ;
313342 private boolean ensureDefaults ;
314343 private JSONObject pluginJson ;
@@ -429,6 +458,24 @@ public Builder syncPageSize(@IntRange(from = 0) Integer syncPageSize) {
429458 return Builder .this ;
430459 }
431460
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+
432479 /**
433480 * Sets a sync expression for a particular model to filter which data is synced locally.
434481 * The expression is evaluated each time DataStore is started.
@@ -518,6 +565,10 @@ private void applyUserProvidedConfiguration() {
518565 syncPageSize = getValueOrDefault (userProvidedConfiguration .getSyncPageSize (), syncPageSize );
519566 syncExpressions = userProvidedConfiguration .getSyncExpressions ();
520567 doSyncRetry = getValueOrDefault (userProvidedConfiguration .getDoSyncRetry (), doSyncRetry );
568+ syncMaxConcurrentModels = getValueOrDefault (
569+ userProvidedConfiguration .getSyncMaxConcurrentModels (),
570+ syncMaxConcurrentModels
571+ );
521572 observeQueryMaxRecords = getValueOrDefault (userProvidedConfiguration .getObserveQueryMaxRecords (),
522573 observeQueryMaxRecords );
523574 maxTimeLapseForObserveQuery = userProvidedConfiguration .getMaxTimeLapseForObserveQuery ()
@@ -548,6 +599,10 @@ public DataStoreConfiguration build() throws DataStoreException {
548599 syncIntervalInMinutes = getValueOrDefault (syncIntervalInMinutes , DEFAULT_SYNC_INTERVAL_MINUTES );
549600 syncMaxRecords = getValueOrDefault (syncMaxRecords , DEFAULT_SYNC_MAX_RECORDS );
550601 syncPageSize = getValueOrDefault (syncPageSize , DEFAULT_SYNC_PAGE_SIZE );
602+ syncMaxConcurrentModels = getValueOrDefault (
603+ syncMaxConcurrentModels ,
604+ DEFAULT_SYNC_MAX_CONCURRENT_MODELS
605+ );
551606 observeQueryMaxRecords = getValueOrDefault (observeQueryMaxRecords , MAX_RECORDS );
552607 maxTimeLapseForObserveQuery = maxTimeLapseForObserveQuery == 0 ? MAX_TIME_SEC :
553608 maxTimeLapseForObserveQuery ;
0 commit comments