Dont exceed max sqlite variables when deleting

pull/685/merge
Alex Baker 7 years ago
parent ef874a8942
commit d2d2316d8e

@ -0,0 +1,36 @@
package org.tasks.data;
import static com.google.common.collect.Lists.newArrayList;
import android.support.test.runner.AndroidJUnit4;
import com.google.common.collect.ContiguousSet;
import com.google.common.collect.DiscreteDomain;
import com.google.common.collect.Range;
import javax.inject.Inject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.injection.InjectingTestCase;
import org.tasks.injection.TestComponent;
@RunWith(AndroidJUnit4.class)
public class DeletionDaoTests extends InjectingTestCase {
@Inject DeletionDao deletionDao;
@Test
public void deleting1000DoesntCrash() {
deletionDao.delete(
newArrayList(ContiguousSet.create(Range.closed(1L, 1000L), DiscreteDomain.longs())));
}
@Test
public void marking998ForDeletionDoesntCrash() {
deletionDao.markDeleted(
newArrayList(ContiguousSet.create(Range.closed(1L, 1000L), DiscreteDomain.longs())));
}
@Override
protected void inject(TestComponent component) {
component.inject(this);
}
}

@ -16,6 +16,7 @@ import com.todoroo.astrid.subtasks.SubtasksHelperTest;
import com.todoroo.astrid.subtasks.SubtasksTestCase;
import com.todoroo.astrid.sync.NewSyncTestCase;
import dagger.Component;
import org.tasks.data.DeletionDaoTests;
import org.tasks.jobs.BackupServiceTests;
@ApplicationScope
@ -53,4 +54,6 @@ public interface TestComponent {
void inject(RepeatTaskHelperTest repeatTaskHelperTest);
void inject(GtasksMetadataServiceTest gtasksMetadataServiceTest);
void inject(DeletionDaoTests deletionDaoTests);
}

@ -1,7 +1,6 @@
package com.todoroo.astrid.service;
import static com.todoroo.andlib.sql.Criterion.all;
import static com.todoroo.andlib.utility.DateUtilities.now;
import static com.todoroo.astrid.dao.TaskDao.TaskCriteria.isVisible;
import static com.todoroo.astrid.dao.TaskDao.TaskCriteria.notCompleted;
@ -46,7 +45,7 @@ public class TaskDeleter {
}
public List<Task> markDeleted(List<Long> taskIds) {
deletionDao.markDeleted(now(), taskIds);
deletionDao.markDeleted(taskIds);
jobManager.cleanup(taskIds);
jobManager.syncNow();
localBroadcastManager.broadcastRefresh();

@ -1,5 +1,8 @@
package org.tasks.data;
import static com.google.common.collect.Iterables.partition;
import static com.todoroo.andlib.utility.DateUtilities.now;
import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Query;
@ -32,12 +35,24 @@ public abstract class DeletionDao {
@Transaction
public void delete(List<Long> ids) {
deleteAlarms(ids);
deleteGeofences(ids);
deleteTags(ids);
deleteGoogleTasks(ids);
deleteCaldavTasks(ids);
deleteTasks(ids);
for (List<Long> partition : partition(ids, 999)) {
deleteAlarms(partition);
deleteGeofences(partition);
deleteTags(partition);
deleteGoogleTasks(partition);
deleteCaldavTasks(partition);
deleteTasks(partition);
}
}
@Query("UPDATE tasks SET modified = :timestamp, deleted = :timestamp WHERE _id IN(:ids)")
abstract void markDeleted(long timestamp, List<Long> ids);
public void markDeleted(List<Long> ids) {
long now = now();
for (List<Long> partition : partition(ids, 997)) {
markDeleted(now, partition);
}
}
@Query("SELECT task FROM google_tasks WHERE deleted = 0 AND list_id = :listId")
@ -70,9 +85,6 @@ public abstract class DeletionDao {
return deleted;
}
@Query("UPDATE tasks SET modified = :timestamp, deleted = :timestamp WHERE _id IN(:ids)")
public abstract void markDeleted(long timestamp, List<Long> ids);
@Query("SELECT task FROM caldav_tasks WHERE calendar = :calendar AND deleted = 0")
abstract List<Long> getActiveCaldavTasks(String calendar);

Loading…
Cancel
Save