From 5ac4e10b1da5a533d46666ad8196f262ee9a38c1 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Fri, 29 Mar 2013 16:23:34 -0700 Subject: [PATCH] Introduce a tag_id history field for better keeping track of history entries that correspond to particular tags --- api/src/com/todoroo/astrid/data/History.java | 8 +++++++- .../todoroo/astrid/actfm/sync/messages/FetchHistory.java | 4 +++- astrid/src/com/todoroo/astrid/dao/Database.java | 8 +++++--- astrid/src/com/todoroo/astrid/service/TagDataService.java | 5 +---- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/api/src/com/todoroo/astrid/data/History.java b/api/src/com/todoroo/astrid/data/History.java index 1c3926c1a..fb34d63c2 100644 --- a/api/src/com/todoroo/astrid/data/History.java +++ b/api/src/com/todoroo/astrid/data/History.java @@ -63,6 +63,11 @@ public class History extends AbstractModel { public static final StringProperty TASK = new StringProperty( TABLE, "task"); + /** Associated tag id */ + public static final StringProperty TAG_ID = new StringProperty( + TABLE, "tag_id"); + + /** Default values container */ private static final ContentValues defaultValues = new ContentValues(); @@ -74,9 +79,10 @@ public class History extends AbstractModel { static { defaultValues.put(UUID.name, 0L); defaultValues.put(CREATED_AT.name, 0L); - defaultValues.put(USER_UUID.name, "0"); + defaultValues.put(USER_UUID.name, RemoteModel.NO_UUID); defaultValues.put(OLD_VALUE.name, ""); defaultValues.put(NEW_VALUE.name, ""); + defaultValues.put(TAG_ID.name, RemoteModel.NO_UUID); defaultValues.put(TASK.name, ""); } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/FetchHistory.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/FetchHistory.java index ff34dafb5..cda80379d 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/FetchHistory.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/FetchHistory.java @@ -107,7 +107,7 @@ public class FetchHistory { History history = new History(); history.setValue(History.TABLE_ID, table); history.setValue(History.TARGET_ID, uuid); - history.setValue(History.UUID, historyJson.optString("id")); + history.setValue(History.UUID, historyJson.optString("id") + ":" + uuid); history.setValue(History.USER_UUID, historyJson.optString("user_id")); history.setValue(History.COLUMN, historyJson.optString("column")); history.setValue(History.OLD_VALUE, historyJson.optString("prev")); @@ -124,6 +124,8 @@ public class FetchHistory { taskObj.put(uuid); taskObj.put(taskTitle); history.setValue(History.TASK, taskObj.toString()); + } else if (NameMaps.TABLE_ID_TAGS.equals(table)) { + history.setValue(History.TAG_ID, uuid); } if (historyDao.update(History.UUID.eq(history.getValue(History.UUID)), history) <= 0) { diff --git a/astrid/src/com/todoroo/astrid/dao/Database.java b/astrid/src/com/todoroo/astrid/dao/Database.java index 08eece3d6..53c331492 100644 --- a/astrid/src/com/todoroo/astrid/dao/Database.java +++ b/astrid/src/com/todoroo/astrid/dao/Database.java @@ -53,7 +53,7 @@ public class Database extends AbstractDatabase { * Database version number. This variable must be updated when database * tables are updated, as it determines whether a database needs updating. */ - public static final int VERSION = 32; + public static final int VERSION = 33; /** * Database name (must be unique) @@ -350,14 +350,12 @@ public class Database extends AbstractDatabase { } case 28: case 29: - tryExecSQL("DROP TABLE " + History.TABLE.name); tryExecSQL(createTableSql(visitor, TaskOutstanding.TABLE.name, TaskOutstanding.PROPERTIES)); tryExecSQL(createTableSql(visitor, TagOutstanding.TABLE.name, TagOutstanding.PROPERTIES)); tryExecSQL(createTableSql(visitor, TaskAttachmentOutstanding.TABLE.name, TagOutstanding.PROPERTIES)); tryExecSQL(createTableSql(visitor, TagMetadata.TABLE.name, TagMetadata.PROPERTIES)); tryExecSQL(createTableSql(visitor, UserActivity.TABLE.name, UserActivity.PROPERTIES)); tryExecSQL(createTableSql(visitor, UserActivityOutstanding.TABLE.name, UserActivityOutstanding.PROPERTIES)); - tryExecSQL(createTableSql(visitor, History.TABLE.name, History.PROPERTIES)); tryExecSQL(createTableSql(visitor, TaskAttachment.TABLE.name, TaskAttachment.PROPERTIES)); tryExecSQL(createTableSql(visitor, TaskListMetadata.TABLE.name, TaskListMetadata.PROPERTIES)); tryExecSQL(createTableSql(visitor, TaskListMetadataOutstanding.TABLE.name, TaskListMetadataOutstanding.PROPERTIES)); @@ -386,6 +384,10 @@ public class Database extends AbstractDatabase { case 31: tryExecSQL(addColumnSql(Task.TABLE, Task.HISTORY_HAS_MORE, visitor, null)); tryExecSQL(addColumnSql(TagData.TABLE, TagData.HISTORY_HAS_MORE, visitor, null)); + case 32: + tryExecSQL("DROP TABLE " + History.TABLE.name); + tryExecSQL(createTableSql(visitor, History.TABLE.name, History.PROPERTIES)); + return true; } diff --git a/astrid/src/com/todoroo/astrid/service/TagDataService.java b/astrid/src/com/todoroo/astrid/service/TagDataService.java index 51b766bd5..58bd139a7 100644 --- a/astrid/src/com/todoroo/astrid/service/TagDataService.java +++ b/astrid/src/com/todoroo/astrid/service/TagDataService.java @@ -23,7 +23,6 @@ import com.todoroo.andlib.sql.Order; import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.astrid.actfm.sync.ActFmSyncService; -import com.todoroo.astrid.actfm.sync.messages.NameMaps; import com.todoroo.astrid.adapter.UpdateAdapter; import com.todoroo.astrid.api.PermaSql; import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; @@ -174,9 +173,7 @@ public class TagDataService { if (tagData == null) historyCriterion = Criterion.none; else - historyCriterion = Criterion.or(Criterion.and(History.TABLE_ID.eq(NameMaps.TABLE_ID_TAGS), History.TARGET_ID.eq(tagData.getUuid())), - Criterion.and(History.TABLE_ID.eq(NameMaps.TABLE_ID_TASKS), History.TARGET_ID.in(Query.select(TaskToTagMetadata.TASK_UUID) - .from(Metadata.TABLE).where(Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY), TaskToTagMetadata.TAG_UUID.eq(tagData.getUuid())))))); + historyCriterion = History.TAG_ID.eq(tagData.getUuid()); Query historyQuery = Query.select(AndroidUtilities.addToArray(UpdateAdapter.HISTORY_PROPERTIES, userProperties)).from(History.TABLE) .where(historyCriterion)