Skip to content

Commit 9204781

Browse files
committed
Remove unused reference; Fix format and comment
1 parent bb25e15 commit 9204781

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/operations/impl/OperationModelStore.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,9 @@ import com.onesignal.user.internal.operations.impl.executors.LoginUserOperationE
2525
import com.onesignal.user.internal.operations.impl.executors.RefreshUserOperationExecutor
2626
import com.onesignal.user.internal.operations.impl.executors.SubscriptionOperationExecutor
2727
import com.onesignal.user.internal.operations.impl.executors.UpdateUserOperationExecutor
28-
import kotlinx.coroutines.Dispatchers
29-
import kotlinx.coroutines.GlobalScope
30-
import kotlinx.coroutines.coroutineScope
31-
import kotlinx.coroutines.launch
3228
import org.json.JSONObject
3329

3430
internal class OperationModelStore(prefs: IPreferencesService) : ModelStore<Operation>("operations", prefs) {
35-
3631
fun loadOperations() {
3732
load()
3833
}

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/operations/impl/OperationRepo.kt

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ internal class OperationRepo(
6969
private val executeBucket get() =
7070
if (enqueueIntoBucket == 0) 0 else enqueueIntoBucket - 1
7171

72-
/**
73-
* Perform initialization in background to prevent possible operation point of failures from
74-
* blocking the creation of OperationRepo.
75-
*/
7672
init {
7773
val executorsMap: MutableMap<String, IOperationExecutor> = mutableMapOf()
7874
for (executor in executors) {
@@ -128,10 +124,11 @@ internal class OperationRepo(
128124
index: Int? = null,
129125
) {
130126
synchronized(queue) {
131-
if (index != null)
127+
if (index != null) {
132128
queue.add(index, queueItem)
133-
else
129+
} else {
134130
queue.add(queueItem)
131+
}
135132
}
136133
if (addToStore) {
137134
_operationModelStore.add(queueItem.operation)
@@ -340,12 +337,20 @@ internal class OperationRepo(
340337
}
341338

342339
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+
}
344345

345346
if (queue.isNotEmpty()) {
346347
for (item in queue.toList()) {
347348
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+
}
349354

350355
if (itemKey == "" && startingKey == "") {
351356
throw Exception("Both comparison keys can not be blank!")
@@ -363,13 +368,18 @@ internal class OperationRepo(
363368

364369
/**
365370
* 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.
367373
*/
368374
private fun loadSavedOperations() {
369-
// load operation in a separate thread to avoid halting the main process
370375
_operationModelStore.loadOperations()
371376
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+
)
373383
}
374384
}
375385
}

OneSignalSDK/onesignal/core/src/test/java/com/onesignal/core/internal/operations/OperationRepoTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private class Mocks {
3535
val operationModelStore: OperationModelStore =
3636
run {
3737
val mockOperationModelStore = mockk<OperationModelStore>()
38-
every {mockOperationModelStore.loadOperations() } just runs
38+
every { mockOperationModelStore.loadOperations() } just runs
3939
every { mockOperationModelStore.list() } returns listOf()
4040
every { mockOperationModelStore.add(any()) } just runs
4141
every { mockOperationModelStore.remove(any()) } just runs

0 commit comments

Comments
 (0)