Recursively delete caldav children

pull/848/head^2
Chris Heywood 5 years ago committed by Alex Baker
parent 2081264a0a
commit e68b49942a

@ -17,6 +17,7 @@ import javax.inject.Inject;
import org.tasks.LocalBroadcastManager; import org.tasks.LocalBroadcastManager;
import org.tasks.data.CaldavAccount; import org.tasks.data.CaldavAccount;
import org.tasks.data.CaldavCalendar; import org.tasks.data.CaldavCalendar;
import org.tasks.data.CaldavDao;
import org.tasks.data.DeletionDao; import org.tasks.data.DeletionDao;
import org.tasks.data.GoogleTaskAccount; import org.tasks.data.GoogleTaskAccount;
import org.tasks.data.GoogleTaskDao; import org.tasks.data.GoogleTaskDao;
@ -29,6 +30,7 @@ public class TaskDeleter {
private final TaskDao taskDao; private final TaskDao taskDao;
private final LocalBroadcastManager localBroadcastManager; private final LocalBroadcastManager localBroadcastManager;
private final GoogleTaskDao googleTaskDao; private final GoogleTaskDao googleTaskDao;
private final CaldavDao caldavDao;
private final DeletionDao deletionDao; private final DeletionDao deletionDao;
@Inject @Inject
@ -37,12 +39,14 @@ public class TaskDeleter {
WorkManager workManager, WorkManager workManager,
TaskDao taskDao, TaskDao taskDao,
LocalBroadcastManager localBroadcastManager, LocalBroadcastManager localBroadcastManager,
GoogleTaskDao googleTaskDao) { GoogleTaskDao googleTaskDao,
CaldavDao caldavDao) {
this.deletionDao = deletionDao; this.deletionDao = deletionDao;
this.workManager = workManager; this.workManager = workManager;
this.taskDao = taskDao; this.taskDao = taskDao;
this.localBroadcastManager = localBroadcastManager; this.localBroadcastManager = localBroadcastManager;
this.googleTaskDao = googleTaskDao; this.googleTaskDao = googleTaskDao;
this.caldavDao = caldavDao;
} }
public int purgeDeleted() { public int purgeDeleted() {
@ -58,6 +62,7 @@ public class TaskDeleter {
public List<Task> markDeleted(List<Long> taskIds) { public List<Task> markDeleted(List<Long> taskIds) {
Set<Long> ids = new HashSet<>(taskIds); Set<Long> ids = new HashSet<>(taskIds);
batch(taskIds, i -> ids.addAll(googleTaskDao.getChildren(i))); batch(taskIds, i -> ids.addAll(googleTaskDao.getChildren(i)));
batch(taskIds, i -> ids.addAll(caldavDao.getChildren(i)));
deletionDao.markDeleted(ids); deletionDao.markDeleted(ids);
workManager.cleanup(taskIds); workManager.cleanup(taskIds);
workManager.sync(false); workManager.sync(false);

@ -110,4 +110,24 @@ public interface CaldavDao {
+ "INNER JOIN caldav_tasks ON cd_task = tasks._id " + "INNER JOIN caldav_tasks ON cd_task = tasks._id "
+ "GROUP BY tasks._id") + "GROUP BY tasks._id")
List<Long> getTasksWithTags(); List<Long> 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<Long> getChildren(List<Long> ids);
} }

Loading…
Cancel
Save