Skip to content

Commit bf8f016

Browse files
committed
Only use "max. operations per yield point" for tasks.org/OpenTasks operations
1 parent d63b6e5 commit bf8f016

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

lib/src/main/kotlin/at/bitfire/ical4android/BatchOperation.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ import java.util.logging.Level
1717
import java.util.logging.Logger
1818

1919
class 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()

lib/src/main/kotlin/at/bitfire/ical4android/DmfsTask.kt

+2-2
Original file line numberDiff line numberDiff 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

lib/src/main/kotlin/at/bitfire/ical4android/DmfsTaskList.kt

+1-1
Original file line numberDiff line numberDiff 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",

0 commit comments

Comments
 (0)