Move some work outside of the transaction

pull/3321/head
Alex Baker 10 months ago
parent 349ff9451f
commit c0067091fa

@ -2,7 +2,10 @@ package com.todoroo.astrid.service
import android.content.Context
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.tasks.LocalBroadcastManager
import org.tasks.caldav.VtodoCache
@ -83,8 +86,11 @@ class TaskDeleter @Inject constructor(
}
private suspend fun cleanup(tasks: List<Long>) {
if (tasks.isEmpty()) {
return
}
notificationManager.cancel(tasks)
tasks.forEach { task ->
notificationManager.cancel(task)
locationDao.getGeofencesForTask(task).forEach {
locationDao.delete(it)
geofenceApi.update(it.place!!)
@ -94,7 +100,11 @@ class TaskDeleter @Inject constructor(
userActivityDao.delete(it)
}
}
coroutineScope {
launch(Dispatchers.IO) {
notificationManager.updateTimerNotification()
deletionDao.purgeDeleted()
}
}
}
}

@ -10,6 +10,8 @@ import com.todoroo.andlib.utility.AndroidUtilities
import com.todoroo.andlib.utility.AndroidUtilities.preUpsideDownCake
import com.todoroo.astrid.utility.Constants
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.data.dao.LocationDao
@ -65,13 +67,21 @@ class NotificationManager @Inject constructor(
@SuppressLint("CheckResult")
suspend fun cancel(ids: Iterable<Long>) {
coroutineScope {
launch {
for (id in ids) {
notificationManager.cancel(id.toInt())
}
}
}
queue.remove(ids)
notificationDao.deleteAll(ids.toList())
coroutineScope {
launch {
notifyTasks(emptyList(), alert = false, nonstop = false, fiveTimes = false)
}
}
}
suspend fun restoreNotifications(cancelExisting: Boolean) {
val notifications = notificationDao.getAllOrdered()

Loading…
Cancel
Save