File tree 3 files changed +9
-9
lines changed
lib/src/main/kotlin/at/bitfire/ical4android
3 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -17,15 +17,14 @@ import java.util.logging.Level
17
17
import java.util.logging.Logger
18
18
19
19
class BatchOperation (
20
- private val providerClient : ContentProviderClient
20
+ private val providerClient : ContentProviderClient ,
21
+ private val maxOperationsPerYieldPoint : Int? = null
21
22
) {
22
23
23
24
companion object {
24
25
25
- /* * Maximum number of operations per yield point. SQLiteContentProvider, which most content providers
26
- * are based on, indicates a value of 500. However to correct value to avoid the [OperationApplicationException]
27
- * seems to be 499. */
28
- const val MAX_OPERATIONS_PER_YIELD_POINT = 499
26
+ /* * Maximum number of operations per yield point in task providers that are based on SQLiteContentProvider. */
27
+ const val TASKS_OPERATIONS_PER_YIELD_POINT = 499
29
28
30
29
}
31
30
@@ -158,7 +157,8 @@ class BatchOperation(
158
157
}
159
158
160
159
// Set a possible yield point every MAX_OPERATIONS_PER_YIELD_POINT operations for SQLiteContentProvider
161
- if ((++ currentIdx).mod(MAX_OPERATIONS_PER_YIELD_POINT ) == 0 )
160
+ currentIdx + = 1
161
+ if (maxOperationsPerYieldPoint != null && currentIdx.mod(maxOperationsPerYieldPoint) == 0 )
162
162
cpoBuilder.withYieldAllowed()
163
163
164
164
cpo + = cpoBuilder.build()
Original file line number Diff line number Diff line change @@ -330,7 +330,7 @@ abstract class DmfsTask(
330
330
331
331
332
332
fun add (): Uri {
333
- val batch = BatchOperation (taskList.provider)
333
+ val batch = BatchOperation (taskList.provider, BatchOperation . TASKS_OPERATIONS_PER_YIELD_POINT )
334
334
335
335
val builder = CpoBuilder .newInsert(taskList.tasksSyncUri())
336
336
buildTask(builder, false )
@@ -350,7 +350,7 @@ abstract class DmfsTask(
350
350
this .task = task
351
351
val existingId = requireNotNull(id)
352
352
353
- val batch = BatchOperation (taskList.provider)
353
+ val batch = BatchOperation (taskList.provider, BatchOperation . TASKS_OPERATIONS_PER_YIELD_POINT )
354
354
355
355
// remove associated rows which are added later again
356
356
batch.enqueue(CpoBuilder
Original file line number Diff line number Diff line change @@ -163,7 +163,7 @@ abstract class DmfsTaskList<out T : DmfsTask>(
163
163
*/
164
164
fun touchRelations (): Int {
165
165
logger.fine(" Touching relations to set parent_id" )
166
- val batchOperation = BatchOperation (provider)
166
+ val batchOperation = BatchOperation (provider, BatchOperation . TASKS_OPERATIONS_PER_YIELD_POINT )
167
167
provider.query(
168
168
tasksSyncUri(true ), null ,
169
169
" ${Tasks .LIST_ID } =? AND ${Tasks .PARENT_ID } IS NULL AND ${Relation .MIMETYPE } =? AND ${Relation .RELATED_ID } IS NOT NULL" ,
You can’t perform that action at this time.
0 commit comments