@@ -69,10 +69,6 @@ internal class OperationRepo(
69
69
private val executeBucket get() =
70
70
if (enqueueIntoBucket == 0 ) 0 else enqueueIntoBucket - 1
71
71
72
- /* *
73
- * Perform initialization in background to prevent possible operation point of failures from
74
- * blocking the creation of OperationRepo.
75
- */
76
72
init {
77
73
val executorsMap: MutableMap <String , IOperationExecutor > = mutableMapOf ()
78
74
for (executor in executors) {
@@ -128,10 +124,11 @@ internal class OperationRepo(
128
124
index : Int? = null,
129
125
) {
130
126
synchronized(queue) {
131
- if (index != null )
127
+ if (index != null ) {
132
128
queue.add(index, queueItem)
133
- else
129
+ } else {
134
130
queue.add(queueItem)
131
+ }
135
132
}
136
133
if (addToStore) {
137
134
_operationModelStore .add(queueItem.operation)
@@ -340,12 +337,20 @@ internal class OperationRepo(
340
337
}
341
338
342
339
val startingKey =
343
- if (startingOp.operation.groupComparisonType == GroupComparisonType .CREATE ) startingOp.operation.createComparisonKey else startingOp.operation.modifyComparisonKey
340
+ if (startingOp.operation.groupComparisonType == GroupComparisonType .CREATE ) {
341
+ startingOp.operation.createComparisonKey
342
+ } else {
343
+ startingOp.operation.modifyComparisonKey
344
+ }
344
345
345
346
if (queue.isNotEmpty()) {
346
347
for (item in queue.toList()) {
347
348
val itemKey =
348
- if (startingOp.operation.groupComparisonType == GroupComparisonType .CREATE ) item.operation.createComparisonKey else item.operation.modifyComparisonKey
349
+ if (startingOp.operation.groupComparisonType == GroupComparisonType .CREATE ) {
350
+ item.operation.createComparisonKey
351
+ } else {
352
+ item.operation.modifyComparisonKey
353
+ }
349
354
350
355
if (itemKey == " " && startingKey == " " ) {
351
356
throw Exception (" Both comparison keys can not be blank!" )
@@ -363,13 +368,18 @@ internal class OperationRepo(
363
368
364
369
/* *
365
370
* Load saved operations from preference service and add them into the queue
366
- * NOTE: sometimes the loading might take longer than expectedly due to device's state
371
+ * NOTE: Sometimes the loading might take longer than expected due to I/O reads from disk
372
+ * Any I/O implies executing time will vary greatly.
367
373
*/
368
374
private fun loadSavedOperations () {
369
- // load operation in a separate thread to avoid halting the main process
370
375
_operationModelStore .loadOperations()
371
376
for (operation in _operationModelStore .list().withIndex()) {
372
- internalEnqueue(OperationQueueItem (operation.value, bucket = enqueueIntoBucket), flush = false , addToStore = false , operation.index)
377
+ internalEnqueue(
378
+ OperationQueueItem (operation.value, bucket = enqueueIntoBucket),
379
+ flush = false ,
380
+ addToStore = false ,
381
+ operation.index,
382
+ )
373
383
}
374
384
}
375
385
}
0 commit comments