From 205295a59a89daac9263d4cfe61d34523463d0f6 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Mon, 29 Jun 2020 14:51:34 -0500 Subject: [PATCH] Tighten access on some dao methods --- .../java/com/todoroo/astrid/dao/TaskDao.kt | 9 ++-- .../com/todoroo/astrid/dao/TaskDaoBlocking.kt | 25 ---------- app/src/main/java/org/tasks/data/CaldavDao.kt | 4 +- .../java/org/tasks/data/CaldavDaoBlocking.kt | 17 ------- .../main/java/org/tasks/data/DeletionDao.kt | 24 +++++----- .../org/tasks/data/DeletionDaoBlocking.kt | 48 ------------------- .../main/java/org/tasks/data/GoogleTaskDao.kt | 10 ++-- .../org/tasks/data/GoogleTaskDaoBlocking.kt | 20 -------- .../main/java/org/tasks/data/TagDataDao.kt | 6 +-- .../java/org/tasks/data/TagDataDaoBlocking.kt | 12 ----- 10 files changed, 25 insertions(+), 150 deletions(-) diff --git a/app/src/main/java/com/todoroo/astrid/dao/TaskDao.kt b/app/src/main/java/com/todoroo/astrid/dao/TaskDao.kt index 9f3349157..4e08a941f 100644 --- a/app/src/main/java/com/todoroo/astrid/dao/TaskDao.kt +++ b/app/src/main/java/com/todoroo/astrid/dao/TaskDao.kt @@ -40,7 +40,7 @@ abstract class TaskDao(private val database: Database) { } @Query("SELECT * FROM tasks WHERE completed = 0 AND deleted = 0 AND (hideUntil > :now OR dueDate > :now)") - abstract suspend fun needsRefresh(now: Long = DateUtilities.now()): List + internal abstract suspend fun needsRefresh(now: Long = DateUtilities.now()): List suspend fun fetchBlocking(id: Long) = runBlocking { fetch(id) @@ -66,9 +66,6 @@ abstract class TaskDao(private val database: Database) { @Query("SELECT * FROM tasks WHERE completed = 0 AND deleted = 0") abstract suspend fun getActiveTasks(): List - @Query("SELECT * FROM tasks WHERE hideUntil < (strftime('%s','now')*1000)") - abstract suspend fun getVisibleTasks(): List - @Query("SELECT * FROM tasks WHERE remoteId IN (:remoteIds) " + "AND recurrence IS NOT NULL AND LENGTH(recurrence) > 0") abstract suspend fun getRecurringTasks(remoteIds: List): List @@ -171,7 +168,7 @@ SELECT EXISTS(SELECT 1 FROM tasks WHERE parent > 0 AND deleted = 0) AS hasSubtas } @Query("UPDATE tasks SET modified = :now WHERE _id in (:ids)") - abstract suspend fun touchInternal(ids: List, now: Long = currentTimeMillis()) + internal abstract suspend fun touchInternal(ids: List, now: Long = currentTimeMillis()) suspend fun setParent(parent: Long, tasks: List) = tasks.eachChunk { setParentInternal(parent, it) } @@ -214,7 +211,7 @@ SELECT EXISTS(SELECT 1 FROM tasks WHERE parent > 0 AND deleted = 0) AS hasSubtas } @Query("UPDATE tasks SET collapsed = :collapsed WHERE _id IN (:ids)") - abstract suspend fun collapse(ids: List, collapsed: Boolean) + internal abstract suspend fun collapse(ids: List, collapsed: Boolean) // --- save // TODO: get rid of this super-hack diff --git a/app/src/main/java/com/todoroo/astrid/dao/TaskDaoBlocking.kt b/app/src/main/java/com/todoroo/astrid/dao/TaskDaoBlocking.kt index 4cc3e03e0..512a4d603 100644 --- a/app/src/main/java/com/todoroo/astrid/dao/TaskDaoBlocking.kt +++ b/app/src/main/java/com/todoroo/astrid/dao/TaskDaoBlocking.kt @@ -13,7 +13,6 @@ import kotlinx.coroutines.runBlocking import org.tasks.data.SubtaskInfo import org.tasks.data.TaskContainer import org.tasks.preferences.Preferences -import org.tasks.time.DateTimeUtils.currentTimeMillis import javax.inject.Inject @Deprecated("use coroutines") @@ -22,10 +21,6 @@ class TaskDaoBlocking @Inject constructor(private val dao: TaskDao) { dao.needsRefresh() } - fun needsRefresh(now: Long): List = runBlocking { - dao.needsRefresh(now) - } - fun fetchBlocking(id: Long) = runBlocking { dao.fetchBlocking(id) } @@ -38,10 +33,6 @@ class TaskDaoBlocking @Inject constructor(private val dao: TaskDao) { dao.fetch(ids) } - internal fun fetchInternal(ids: List): List = runBlocking { - dao.fetchInternal(ids) - } - fun activeTimers(): Int = runBlocking { dao.activeTimers() } @@ -58,10 +49,6 @@ class TaskDaoBlocking @Inject constructor(private val dao: TaskDao) { dao.getActiveTasks() } - fun getVisibleTasks(): List = runBlocking { - dao.getVisibleTasks() - } - fun getRecurringTasks(remoteIds: List): List = runBlocking { dao.getRecurringTasks(remoteIds) } @@ -142,18 +129,10 @@ class TaskDaoBlocking @Inject constructor(private val dao: TaskDao) { dao.touch(ids) } - fun touchInternal(ids: List, now: Long = currentTimeMillis()) = runBlocking { - dao.touchInternal(ids, now) - } - fun setParent(parent: Long, tasks: List) = runBlocking { dao.setParent(parent, tasks) } - internal fun setParentInternal(parent: Long, children: List) = runBlocking { - dao.setParentInternal(parent, children) - } - fun fetchChildren(id: Long): List = runBlocking { dao.fetchChildren(id) } @@ -174,10 +153,6 @@ class TaskDaoBlocking @Inject constructor(private val dao: TaskDao) { dao.setCollapsed(preferences, filter, collapsed) } - fun collapse(ids: List, collapsed: Boolean) = runBlocking { - dao.collapse(ids, collapsed) - } - fun save(task: Task) = runBlocking { dao.save(task) } diff --git a/app/src/main/java/org/tasks/data/CaldavDao.kt b/app/src/main/java/org/tasks/data/CaldavDao.kt index 3fe2b5f74..9489b6805 100644 --- a/app/src/main/java/org/tasks/data/CaldavDao.kt +++ b/app/src/main/java/org/tasks/data/CaldavDao.kt @@ -48,7 +48,7 @@ abstract class CaldavDao { } @Insert - abstract suspend fun insertInternal(caldavCalendar: CaldavCalendar): Long + internal abstract suspend fun insertInternal(caldavCalendar: CaldavCalendar): Long @Update abstract suspend fun update(caldavCalendar: CaldavCalendar) @@ -153,7 +153,7 @@ abstract class CaldavDao { objects.chunkedMap { getTasksInternal(calendar, it) } @Query("SELECT cd_task FROM caldav_tasks WHERE cd_calendar = :calendar AND cd_object IN (:objects)") - abstract suspend fun getTasksInternal(calendar: String, objects: List): List + internal abstract suspend fun getTasksInternal(calendar: String, objects: List): List @Query("SELECT * FROM caldav_lists WHERE cdl_account = :account AND cdl_url NOT IN (:urls)") abstract suspend fun findDeletedCalendars(account: String, urls: List): List diff --git a/app/src/main/java/org/tasks/data/CaldavDaoBlocking.kt b/app/src/main/java/org/tasks/data/CaldavDaoBlocking.kt index 8f58b40fe..b114a42fa 100644 --- a/app/src/main/java/org/tasks/data/CaldavDaoBlocking.kt +++ b/app/src/main/java/org/tasks/data/CaldavDaoBlocking.kt @@ -2,7 +2,6 @@ package org.tasks.data import android.content.Context import androidx.lifecycle.LiveData -import com.todoroo.andlib.utility.DateUtilities.now import com.todoroo.astrid.data.Task import kotlinx.coroutines.runBlocking import org.tasks.filters.CaldavFilters @@ -51,10 +50,6 @@ class CaldavDaoBlocking @Inject constructor(private val dao: CaldavDao) { dao.insert(caldavCalendar) } - fun insertInternal(caldavCalendar: CaldavCalendar): Long = runBlocking { - dao.insertInternal(caldavCalendar) - } - fun update(caldavCalendar: CaldavCalendar) = runBlocking { dao.update(caldavCalendar) } @@ -163,10 +158,6 @@ class CaldavDaoBlocking @Inject constructor(private val dao: CaldavDao) { dao.getTasks(calendar, objects) } - fun getTasksInternal(calendar: String, objects: List): List = runBlocking { - dao.getTasksInternal(calendar, objects) - } - fun findDeletedCalendars(account: String, urls: List): List = runBlocking { dao.findDeletedCalendars(account, urls) } @@ -207,14 +198,6 @@ class CaldavDaoBlocking @Inject constructor(private val dao: CaldavDao) { dao.shiftDown(calendar, parent, from, to) } - internal fun touchInternal(ids: List, modificationTime: Long = now()) = runBlocking { - dao.touchInternal(ids, modificationTime) - } - - internal fun getTasksToShift(calendar: String, parent: Long, from: Long, to: Long?): List = runBlocking { - dao.getTasksToShift(calendar, parent, from, to) - } - fun resetOrders() = runBlocking { dao.resetOrders() } diff --git a/app/src/main/java/org/tasks/data/DeletionDao.kt b/app/src/main/java/org/tasks/data/DeletionDao.kt index 2ef3e9803..2f95e067e 100644 --- a/app/src/main/java/org/tasks/data/DeletionDao.kt +++ b/app/src/main/java/org/tasks/data/DeletionDao.kt @@ -11,22 +11,22 @@ import java.util.* @Dao abstract class DeletionDao { @Query("DELETE FROM caldav_tasks WHERE cd_task IN(:ids)") - abstract suspend fun deleteCaldavTasks(ids: List) + internal abstract suspend fun deleteCaldavTasks(ids: List) @Query("DELETE FROM google_tasks WHERE gt_task IN(:ids)") - abstract suspend fun deleteGoogleTasks(ids: List) + internal abstract suspend fun deleteGoogleTasks(ids: List) @Query("DELETE FROM tags WHERE task IN(:ids)") abstract suspend fun deleteTags(ids: List) @Query("DELETE FROM geofences WHERE task IN(:ids)") - abstract suspend fun deleteGeofences(ids: List) + internal abstract suspend fun deleteGeofences(ids: List) @Query("DELETE FROM alarms WHERE task IN(:ids)") - abstract suspend fun deleteAlarms(ids: List) + internal abstract suspend fun deleteAlarms(ids: List) @Query("DELETE FROM tasks WHERE _id IN(:ids)") - abstract suspend fun deleteTasks(ids: List) + internal abstract suspend fun deleteTasks(ids: List) @Transaction open suspend fun delete(ids: List) { @@ -43,17 +43,17 @@ abstract class DeletionDao { @Query("UPDATE tasks " + "SET modified = (strftime('%s','now')*1000), deleted = (strftime('%s','now')*1000)" + "WHERE _id IN(:ids)") - abstract suspend fun markDeletedInternal(ids: List) + internal abstract suspend fun markDeletedInternal(ids: List) suspend fun markDeleted(ids: Iterable) { ids.eachChunk(this::markDeletedInternal) } @Query("SELECT gt_task FROM google_tasks WHERE gt_deleted = 0 AND gt_list_id = :listId") - abstract suspend fun getActiveGoogleTasks(listId: String): List + internal abstract suspend fun getActiveGoogleTasks(listId: String): List @Delete - abstract suspend fun deleteGoogleTaskList(googleTaskList: GoogleTaskList) + internal abstract suspend fun deleteGoogleTaskList(googleTaskList: GoogleTaskList) @Transaction open suspend fun delete(googleTaskList: GoogleTaskList): List { @@ -64,7 +64,7 @@ abstract class DeletionDao { } @Delete - abstract suspend fun deleteGoogleTaskAccount(googleTaskAccount: GoogleTaskAccount) + internal abstract suspend fun deleteGoogleTaskAccount(googleTaskAccount: GoogleTaskAccount) @Query("SELECT * FROM google_task_lists WHERE gtl_account = :account ORDER BY gtl_title ASC") abstract suspend fun getLists(account: String): List @@ -80,10 +80,10 @@ abstract class DeletionDao { } @Query("SELECT cd_task FROM caldav_tasks WHERE cd_calendar = :calendar AND cd_deleted = 0") - abstract suspend fun getActiveCaldavTasks(calendar: String): List + internal abstract suspend fun getActiveCaldavTasks(calendar: String): List @Delete - abstract suspend fun deleteCaldavCalendar(caldavCalendar: CaldavCalendar) + internal abstract suspend fun deleteCaldavCalendar(caldavCalendar: CaldavCalendar) @Transaction open suspend fun delete(caldavCalendar: CaldavCalendar): List { @@ -97,7 +97,7 @@ abstract class DeletionDao { abstract suspend fun getCalendars(account: String): List @Delete - abstract suspend fun deleteCaldavAccount(caldavAccount: CaldavAccount) + internal abstract suspend fun deleteCaldavAccount(caldavAccount: CaldavAccount) @Query("DELETE FROM tasks WHERE _id IN (SELECT _id FROM tasks INNER JOIN caldav_tasks ON _id = cd_task INNER JOIN caldav_lists ON cdl_uuid = cd_calendar WHERE cdl_account = '$LOCAL' AND deleted > 0)") abstract suspend fun purgeDeleted() diff --git a/app/src/main/java/org/tasks/data/DeletionDaoBlocking.kt b/app/src/main/java/org/tasks/data/DeletionDaoBlocking.kt index a89b1a862..39963ca70 100644 --- a/app/src/main/java/org/tasks/data/DeletionDaoBlocking.kt +++ b/app/src/main/java/org/tasks/data/DeletionDaoBlocking.kt @@ -5,58 +5,22 @@ import javax.inject.Inject @Deprecated("use coroutines") class DeletionDaoBlocking @Inject constructor(private val dao: DeletionDao) { - fun deleteCaldavTasks(ids: List) = runBlocking { - dao.deleteCaldavTasks(ids) - } - - fun deleteGoogleTasks(ids: List) = runBlocking { - dao.deleteGoogleTasks(ids) - } - fun deleteTags(ids: List) = runBlocking { dao.deleteTags(ids) } - fun deleteGeofences(ids: List) = runBlocking { - dao.deleteGeofences(ids) - } - - fun deleteAlarms(ids: List) = runBlocking { - dao.deleteAlarms(ids) - } - - fun deleteTasks(ids: List) = runBlocking { - dao.deleteTasks(ids) - } - fun delete(ids: List) = runBlocking { dao.delete(ids) } - fun markDeletedInternal(ids: List) = runBlocking { - dao.markDeletedInternal(ids) - } - fun markDeleted(ids: Iterable) = runBlocking { dao.markDeleted(ids) } - fun getActiveGoogleTasks(listId: String): List = runBlocking { - dao.getActiveGoogleTasks(listId) - } - - fun deleteGoogleTaskList(googleTaskList: GoogleTaskList) = runBlocking { - dao.deleteGoogleTaskList(googleTaskList) - } - fun delete(googleTaskList: GoogleTaskList): List = runBlocking { dao.delete(googleTaskList) } - fun deleteGoogleTaskAccount(googleTaskAccount: GoogleTaskAccount) = runBlocking { - dao.deleteGoogleTaskAccount(googleTaskAccount) - } - fun getLists(account: String): List = runBlocking { dao.getLists(account) } @@ -65,14 +29,6 @@ class DeletionDaoBlocking @Inject constructor(private val dao: DeletionDao) { dao.delete(googleTaskAccount) } - fun getActiveCaldavTasks(calendar: String): List = runBlocking { - dao.getActiveCaldavTasks(calendar) - } - - fun deleteCaldavCalendar(caldavCalendar: CaldavCalendar) = runBlocking { - dao.deleteCaldavCalendar(caldavCalendar) - } - fun delete(caldavCalendar: CaldavCalendar): List = runBlocking { dao.delete(caldavCalendar) } @@ -81,10 +37,6 @@ class DeletionDaoBlocking @Inject constructor(private val dao: DeletionDao) { dao.getCalendars(account) } - fun deleteCaldavAccount(caldavAccount: CaldavAccount) = runBlocking { - dao.deleteCaldavAccount(caldavAccount) - } - fun purgeDeleted() = runBlocking { dao.purgeDeleted() } diff --git a/app/src/main/java/org/tasks/data/GoogleTaskDao.kt b/app/src/main/java/org/tasks/data/GoogleTaskDao.kt index f35f7d536..25402c6a9 100644 --- a/app/src/main/java/org/tasks/data/GoogleTaskDao.kt +++ b/app/src/main/java/org/tasks/data/GoogleTaskDao.kt @@ -24,16 +24,16 @@ abstract class GoogleTaskDao { } @Query("UPDATE google_tasks SET gt_order = gt_order + 1 WHERE gt_list_id = :listId AND gt_parent = :parent AND gt_order >= :position") - abstract suspend fun shiftDown(listId: String, parent: Long, position: Long) + internal abstract suspend fun shiftDown(listId: String, parent: Long, position: Long) @Query("UPDATE google_tasks SET gt_order = gt_order - 1 WHERE gt_list_id = :listId AND gt_parent = :parent AND gt_order > :from AND gt_order <= :to") - abstract suspend fun shiftUp(listId: String, parent: Long, from: Long, to: Long) + internal abstract suspend fun shiftUp(listId: String, parent: Long, from: Long, to: Long) @Query("UPDATE google_tasks SET gt_order = gt_order + 1 WHERE gt_list_id = :listId AND gt_parent = :parent AND gt_order < :from AND gt_order >= :to") - abstract suspend fun shiftDown(listId: String, parent: Long, from: Long, to: Long) + internal abstract suspend fun shiftDown(listId: String, parent: Long, from: Long, to: Long) @Query("UPDATE google_tasks SET gt_order = gt_order - 1 WHERE gt_list_id = :listId AND gt_parent = :parent AND gt_order >= :position") - abstract suspend fun shiftUp(listId: String, parent: Long, position: Long) + internal abstract suspend fun shiftUp(listId: String, parent: Long, position: Long) @Transaction open suspend fun move(task: SubsetGoogleTask, newParent: Long, newPosition: Long) { @@ -115,7 +115,7 @@ abstract class GoogleTaskDao { @SuppressWarnings(RoomWarnings.CURSOR_MISMATCH) @Query("SELECT google_tasks.*, gt_remote_order AS primary_sort, NULL AS secondary_sort FROM google_tasks JOIN tasks ON tasks._id = gt_task WHERE gt_parent = 0 AND gt_list_id = :listId AND tasks.deleted = 0 UNION SELECT c.*, p.gt_remote_order AS primary_sort, c.gt_remote_order AS secondary_sort FROM google_tasks AS c LEFT JOIN google_tasks AS p ON c.gt_parent = p.gt_task JOIN tasks ON tasks._id = c.gt_task WHERE c.gt_parent > 0 AND c.gt_list_id = :listId AND tasks.deleted = 0 ORDER BY primary_sort ASC, secondary_sort ASC") - abstract suspend fun getByRemoteOrder(listId: String): List + internal abstract suspend fun getByRemoteOrder(listId: String): List @Query("UPDATE google_tasks" + " SET gt_parent = IFNULL((" diff --git a/app/src/main/java/org/tasks/data/GoogleTaskDaoBlocking.kt b/app/src/main/java/org/tasks/data/GoogleTaskDaoBlocking.kt index c90f587b4..1d2f5faf9 100644 --- a/app/src/main/java/org/tasks/data/GoogleTaskDaoBlocking.kt +++ b/app/src/main/java/org/tasks/data/GoogleTaskDaoBlocking.kt @@ -19,22 +19,6 @@ class GoogleTaskDaoBlocking @Inject constructor(private val dao: GoogleTaskDao) dao.insertAndShift(task, top) } - fun shiftDown(listId: String, parent: Long, position: Long) = runBlocking { - dao.shiftDown(listId, parent, position) - } - - fun shiftUp(listId: String, parent: Long, from: Long, to: Long) = runBlocking { - dao.shiftUp(listId, parent, from, to) - } - - fun shiftDown(listId: String, parent: Long, from: Long, to: Long) = runBlocking { - dao.shiftDown(listId, parent, from, to) - } - - fun shiftUp(listId: String, parent: Long, position: Long) = runBlocking { - dao.shiftUp(listId, parent, position) - } - fun move(task: SubsetGoogleTask, newParent: Long, newPosition: Long) = runBlocking { dao.move(task, newParent, newPosition) } @@ -111,10 +95,6 @@ class GoogleTaskDaoBlocking @Inject constructor(private val dao: GoogleTaskDao) dao.getByLocalOrder(listId) } - fun getByRemoteOrder(listId: String): List = runBlocking { - dao.getByRemoteOrder(listId) - } - fun updateParents() = runBlocking { dao.updateParents() } diff --git a/app/src/main/java/org/tasks/data/TagDataDao.kt b/app/src/main/java/org/tasks/data/TagDataDao.kt index a90e9012a..1e70b57e6 100644 --- a/app/src/main/java/org/tasks/data/TagDataDao.kt +++ b/app/src/main/java/org/tasks/data/TagDataDao.kt @@ -51,13 +51,13 @@ abstract class TagDataDao { abstract suspend fun tagDataOrderedByName(): List @Delete - abstract suspend fun deleteTagData(tagData: TagData) + internal abstract suspend fun deleteTagData(tagData: TagData) @Query("DELETE FROM tags WHERE tag_uid = :tagUid") abstract suspend fun deleteTags(tagUid: String) @Query("SELECT * FROM tags WHERE task IN (:tasks) AND tag_uid NOT IN (:tagsToKeep)") - abstract suspend fun tagsToDelete(tasks: List, tagsToKeep: List): List + internal abstract suspend fun tagsToDelete(tasks: List, tagsToKeep: List): List suspend fun getTagSelections(tasks: List): Pair, Set> { val allTags = getAllTags(tasks) @@ -83,7 +83,7 @@ abstract class TagDataDao { + " LEFT JOIN tags ON tags.task = tasks._id" + " WHERE tasks._id IN (:tasks)" + " GROUP BY tasks._id") - abstract suspend fun getAllTags(tasks: List): List + internal abstract suspend fun getAllTags(tasks: List): List @Transaction open suspend fun applyTags( diff --git a/app/src/main/java/org/tasks/data/TagDataDaoBlocking.kt b/app/src/main/java/org/tasks/data/TagDataDaoBlocking.kt index 2258332d4..c03f8e849 100644 --- a/app/src/main/java/org/tasks/data/TagDataDaoBlocking.kt +++ b/app/src/main/java/org/tasks/data/TagDataDaoBlocking.kt @@ -42,26 +42,14 @@ class TagDataDaoBlocking @Inject constructor(private val dao: TagDataDao) { dao.tagDataOrderedByName() } - fun deleteTagData(tagData: TagData) = runBlocking { - dao.deleteTagData(tagData) - } - fun deleteTags(tagUid: String) = runBlocking { dao.deleteTags(tagUid) } - fun tagsToDelete(tasks: List, tagsToKeep: List): List = runBlocking { - dao.tagsToDelete(tasks, tagsToKeep) - } - fun getTagSelections(tasks: List): Pair, Set> = runBlocking { dao.getTagSelections(tasks) } - fun getAllTags(tasks: List): List = runBlocking { - dao.getAllTags(tasks) - } - fun applyTags(tasks: List, partiallySelected: List, selected: List): List = runBlocking { dao.applyTags(tasks, partiallySelected, selected) }