This repository was archived by the owner on Jun 9, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +9
-9
lines changed
lib/src/main/kotlin/at/bitfire/ical4android Expand file tree Collapse file tree 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
1717import java.util.logging.Logger
1818
1919class BatchOperation (
20- private val providerClient : ContentProviderClient
20+ private val providerClient : ContentProviderClient ,
21+ private val maxOperationsPerYieldPoint : Int? = null
2122) {
2223
2324 companion object {
2425
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
2928
3029 }
3130
@@ -158,7 +157,8 @@ class BatchOperation(
158157 }
159158
160159 // 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 )
162162 cpoBuilder.withYieldAllowed()
163163
164164 cpo + = cpoBuilder.build()
Original file line number Diff line number Diff line change @@ -330,7 +330,7 @@ abstract class DmfsTask(
330330
331331
332332 fun add (): Uri {
333- val batch = BatchOperation (taskList.provider)
333+ val batch = BatchOperation (taskList.provider, BatchOperation . TASKS_OPERATIONS_PER_YIELD_POINT )
334334
335335 val builder = CpoBuilder .newInsert(taskList.tasksSyncUri())
336336 buildTask(builder, false )
@@ -350,7 +350,7 @@ abstract class DmfsTask(
350350 this .task = task
351351 val existingId = requireNotNull(id)
352352
353- val batch = BatchOperation (taskList.provider)
353+ val batch = BatchOperation (taskList.provider, BatchOperation . TASKS_OPERATIONS_PER_YIELD_POINT )
354354
355355 // remove associated rows which are added later again
356356 batch.enqueue(CpoBuilder
Original file line number Diff line number Diff line change @@ -163,7 +163,7 @@ abstract class DmfsTaskList<out T : DmfsTask>(
163163 */
164164 fun touchRelations (): Int {
165165 logger.fine(" Touching relations to set parent_id" )
166- val batchOperation = BatchOperation (provider)
166+ val batchOperation = BatchOperation (provider, BatchOperation . TASKS_OPERATIONS_PER_YIELD_POINT )
167167 provider.query(
168168 tasksSyncUri(true ), null ,
169169 " ${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