From e68b49942a3188246720c0de410d006a514c5318 Mon Sep 17 00:00:00 2001 From: Chris Heywood <31988069+creywood@users.noreply.github.com> Date: Tue, 15 Oct 2019 19:58:52 +0200 Subject: [PATCH] Recursively delete caldav children --- .../todoroo/astrid/service/TaskDeleter.java | 7 ++++++- .../main/java/org/tasks/data/CaldavDao.java | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/todoroo/astrid/service/TaskDeleter.java b/app/src/main/java/com/todoroo/astrid/service/TaskDeleter.java index 8d101b87a..4cf1e0ade 100644 --- a/app/src/main/java/com/todoroo/astrid/service/TaskDeleter.java +++ b/app/src/main/java/com/todoroo/astrid/service/TaskDeleter.java @@ -17,6 +17,7 @@ import javax.inject.Inject; import org.tasks.LocalBroadcastManager; import org.tasks.data.CaldavAccount; import org.tasks.data.CaldavCalendar; +import org.tasks.data.CaldavDao; import org.tasks.data.DeletionDao; import org.tasks.data.GoogleTaskAccount; import org.tasks.data.GoogleTaskDao; @@ -29,6 +30,7 @@ public class TaskDeleter { private final TaskDao taskDao; private final LocalBroadcastManager localBroadcastManager; private final GoogleTaskDao googleTaskDao; + private final CaldavDao caldavDao; private final DeletionDao deletionDao; @Inject @@ -37,12 +39,14 @@ public class TaskDeleter { WorkManager workManager, TaskDao taskDao, LocalBroadcastManager localBroadcastManager, - GoogleTaskDao googleTaskDao) { + GoogleTaskDao googleTaskDao, + CaldavDao caldavDao) { this.deletionDao = deletionDao; this.workManager = workManager; this.taskDao = taskDao; this.localBroadcastManager = localBroadcastManager; this.googleTaskDao = googleTaskDao; + this.caldavDao = caldavDao; } public int purgeDeleted() { @@ -58,6 +62,7 @@ public class TaskDeleter { public List markDeleted(List taskIds) { Set ids = new HashSet<>(taskIds); batch(taskIds, i -> ids.addAll(googleTaskDao.getChildren(i))); + batch(taskIds, i -> ids.addAll(caldavDao.getChildren(i))); deletionDao.markDeleted(ids); workManager.cleanup(taskIds); workManager.sync(false); diff --git a/app/src/main/java/org/tasks/data/CaldavDao.java b/app/src/main/java/org/tasks/data/CaldavDao.java index 4f06f526f..9ff7b93da 100644 --- a/app/src/main/java/org/tasks/data/CaldavDao.java +++ b/app/src/main/java/org/tasks/data/CaldavDao.java @@ -110,4 +110,24 @@ public interface CaldavDao { + "INNER JOIN caldav_tasks ON cd_task = tasks._id " + "GROUP BY tasks._id") List getTasksWithTags(); + + @Query("WITH RECURSIVE " + + " recursive_caldav (cd_task) AS ( " + + " SELECT cd_task " + + " FROM tasks " + + " INNER JOIN caldav_tasks " + + " ON _id = cd_task " + + " WHERE cd_parent IN (:ids) " + + " AND tasks.deleted = 0 " + + "UNION ALL " + + " SELECT caldav_tasks.cd_task " + + " FROM tasks " + + " INNER JOIN caldav_tasks " + + " ON _id = caldav_tasks.cd_task " + + " INNER JOIN recursive_caldav " + + " ON recursive_caldav.cd_task = caldav_tasks.cd_parent " + + " WHERE tasks.deleted = 0 " + + " ) " + + "SELECT cd_task FROM recursive_caldav") + List getChildren(List ids); }