From 3e6c67a3c36ce40330f03f0540e05f9bb99ffff7 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Fri, 1 Mar 2013 11:36:00 -0800 Subject: [PATCH] Fixed several bugs related to constructing outstanding tables after login --- .../astrid/actfm/sync/ActFmInvoker.java | 2 +- .../astrid/actfm/sync/ActFmSyncThread.java | 25 +++++++++++++++---- .../messages/ReplayOutstandingEntries.java | 20 +++++++-------- .../ReplayTaskListMetadataOutstanding.java | 19 ++++++++++++++ .../TaskListMetadataChangesHappened.java | 2 +- 5 files changed, 51 insertions(+), 17 deletions(-) create mode 100644 astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ReplayTaskListMetadataOutstanding.java diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmInvoker.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmInvoker.java index 4d878af5f..9e013d1be 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmInvoker.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmInvoker.java @@ -40,7 +40,7 @@ import com.todoroo.astrid.utility.Constants; public class ActFmInvoker { /** NOTE: these values are development values & will not work on production */ - private static final String URL = "//192.168.0.160:3000/api/"; + private static final String URL = "//192.168.0.100:3000/api/"; private static final String APP_ID = "a4732a32859dbcd3e684331acd36432c"; private static final String APP_SECRET = "e389bfc82a0d932332f9a8bd8203735f"; diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java index cad1d135d..eafa8079e 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java @@ -25,7 +25,9 @@ import com.todoroo.astrid.actfm.sync.messages.ChangesHappened; import com.todoroo.astrid.actfm.sync.messages.ClientToServerMessage; import com.todoroo.astrid.actfm.sync.messages.NameMaps; import com.todoroo.astrid.actfm.sync.messages.ReplayOutstandingEntries; +import com.todoroo.astrid.actfm.sync.messages.ReplayTaskListMetadataOutstanding; import com.todoroo.astrid.actfm.sync.messages.ServerToClientMessage; +import com.todoroo.astrid.actfm.sync.messages.TaskListMetadataChangesHappened; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.dao.OutstandingEntryDao; @@ -298,9 +300,9 @@ public class ActFmSyncThread { // Called after a batch has finished processing private void replayOutstandingChanges(boolean afterErrors) { syncLog("Replaying outstanding changes"); //$NON-NLS-1$ - new ReplayOutstandingEntries(Task.class, NameMaps.TABLE_ID_TASKS, taskDao, taskOutstandingDao, this, afterErrors).execute(); - new ReplayOutstandingEntries(TagData.class, NameMaps.TABLE_ID_TAGS, tagDataDao, tagOutstandingDao, this, afterErrors).execute(); - new ReplayOutstandingEntries(TaskListMetadata.class, NameMaps.TABLE_ID_TASK_LIST_METADATA, taskListMetadataDao, taskListMetadataOutstandingDao, this, afterErrors).execute(); + new ReplayOutstandingEntries(Task.class, NameMaps.TABLE_ID_TASKS, taskDao, taskOutstandingDao, afterErrors).execute(); + new ReplayOutstandingEntries(TagData.class, NameMaps.TABLE_ID_TAGS, tagDataDao, tagOutstandingDao, afterErrors).execute(); + new ReplayTaskListMetadataOutstanding(taskListMetadataDao, taskListMetadataOutstandingDao, afterErrors).execute(); } private boolean timeForBackgroundSync() { @@ -308,9 +310,11 @@ public class ActFmSyncThread { } public void repopulateQueueFromOutstandingTables() { + syncLog("Constructing queue from outstanding tables"); //$NON-NLS-1$ constructChangesHappenedFromOutstandingTable(Task.class, taskDao, taskOutstandingDao); constructChangesHappenedFromOutstandingTable(TagData.class, tagDataDao, tagOutstandingDao); constructChangesHappenedFromOutstandingTable(UserActivity.class, userActivityDao, userActivityOutstandingDao); + constructChangesHappenedForTaskListMetadata(taskListMetadataDao, taskListMetadataOutstandingDao); } private > void constructChangesHappenedFromOutstandingTable(Class modelClass, RemoteModelDao modelDao, OutstandingEntryDao oustandingDao) { @@ -318,8 +322,19 @@ public class ActFmSyncThread { try { for (outstanding.moveToFirst(); !outstanding.isAfterLast(); outstanding.moveToNext()) { Long id = outstanding.get(OutstandingEntry.ENTITY_ID_PROPERTY); - ChangesHappened ch = new ChangesHappened(id, modelClass, modelDao, oustandingDao); - enqueueMessage(ch, null); + enqueueMessage(new ChangesHappened(id, modelClass, modelDao, oustandingDao), null); + } + } finally { + outstanding.close(); + } + } + + private void constructChangesHappenedForTaskListMetadata(TaskListMetadataDao dao, TaskListMetadataOutstandingDao outstandingDao) { + TodorooCursor outstanding = outstandingDao.query(Query.select(OutstandingEntry.ENTITY_ID_PROPERTY).groupBy(OutstandingEntry.ENTITY_ID_PROPERTY)); + try { + for (outstanding.moveToFirst(); !outstanding.isAfterLast(); outstanding.moveToNext()) { + Long id = outstanding.get(OutstandingEntry.ENTITY_ID_PROPERTY); + ActFmSyncWaitingPool.getInstance().enqueueMessage(new TaskListMetadataChangesHappened(id, TaskListMetadata.class, dao, outstandingDao)); } } finally { outstanding.close(); diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ReplayOutstandingEntries.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ReplayOutstandingEntries.java index c2b5d21f0..a813434f1 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ReplayOutstandingEntries.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ReplayOutstandingEntries.java @@ -20,22 +20,19 @@ public class ReplayOutstandingEntries modelClass; + protected final Class modelClass; private final Class outstandingClass; private final String table; - private final RemoteModelDao dao; - private final OutstandingEntryDao outstandingDao; - private final ActFmSyncThread actFmSyncThread; + protected final RemoteModelDao dao; + protected final OutstandingEntryDao outstandingDao; private final boolean afterErrors; - public ReplayOutstandingEntries(Class modelClass, String table, RemoteModelDao dao, OutstandingEntryDao outstandingDao, - ActFmSyncThread actFmSyncThread, boolean afterErrors) { + public ReplayOutstandingEntries(Class modelClass, String table, RemoteModelDao dao, OutstandingEntryDao outstandingDao, boolean afterErrors) { this.modelClass = modelClass; this.outstandingClass = DaoReflectionHelpers.getOutstandingClass(modelClass); this.table = table; this.dao = dao; this.outstandingDao = outstandingDao; - this.actFmSyncThread = actFmSyncThread; this.afterErrors = afterErrors; } @@ -58,6 +55,10 @@ public class ReplayOutstandingEntries(id, modelClass, dao, outstandingDao), null); + } + private void processItem(long id, OE instance, TodorooCursor outstanding) { try { T model = modelClass.newInstance(); @@ -80,9 +81,8 @@ public class ReplayOutstandingEntries 0 && !afterErrors && actFmSyncThread != null) { - ChangesHappened ch = new ChangesHappened(id, modelClass, dao, outstandingDao); - actFmSyncThread.enqueueMessage(ch, null); + if (count > 0 && !afterErrors) { + enqueueChangesHappenedMessage(id); } outstanding.moveToPrevious(); // Move back one to undo the last iteration of the for loop diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ReplayTaskListMetadataOutstanding.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ReplayTaskListMetadataOutstanding.java new file mode 100644 index 000000000..6b7ccaa58 --- /dev/null +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ReplayTaskListMetadataOutstanding.java @@ -0,0 +1,19 @@ +package com.todoroo.astrid.actfm.sync.messages; + +import com.todoroo.astrid.dao.TaskListMetadataDao; +import com.todoroo.astrid.dao.TaskListMetadataOutstandingDao; +import com.todoroo.astrid.data.TaskListMetadata; +import com.todoroo.astrid.data.TaskListMetadataOutstanding; + +public class ReplayTaskListMetadataOutstanding extends ReplayOutstandingEntries { + + public ReplayTaskListMetadataOutstanding(TaskListMetadataDao dao, TaskListMetadataOutstandingDao outstandingDao, boolean afterErrors) { + super(TaskListMetadata.class, NameMaps.TABLE_ID_TASK_LIST_METADATA, dao, outstandingDao, afterErrors); + } + + @Override + protected void enqueueChangesHappenedMessage(long id) { + // Do nothing + } + +} diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/TaskListMetadataChangesHappened.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/TaskListMetadataChangesHappened.java index 6e0f63b09..bdac567cf 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/TaskListMetadataChangesHappened.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/TaskListMetadataChangesHappened.java @@ -32,7 +32,7 @@ public class TaskListMetadataChangesHappened extends ChangesHappened