Don't enqueue empty changeshappened messages, small fix to makechanges

pull/14/head
Sam Bosley 12 years ago
parent 01b3035cf2
commit 2c147d178f

@ -22,10 +22,13 @@ public class SyncDatabaseListener<MTYPE extends RemoteModel> implements ModelUpd
@Override @Override
public void onModelUpdated(MTYPE model) { public void onModelUpdated(MTYPE model) {
queue.add(ChangesHappened.instantiateChangesHappened(model.getId(), modelType)); ChangesHappened<?, ?> ch = ChangesHappened.instantiateChangesHappened(model.getId(), modelType);
if (ch.numChanges() > 0) {
queue.add(ch);
synchronized(monitor) { synchronized(monitor) {
monitor.notifyAll(); monitor.notifyAll();
} }
} }
}
} }

@ -105,7 +105,7 @@ public class ChangesHappened<TYPE extends RemoteModel, OE extends OutstandingEnt
Log.e(ERROR_TAG, "Error writing change to JSON", e); Log.e(ERROR_TAG, "Error writing change to JSON", e);
} }
} }
if (pushedAt == 0) { if (pushedAt == 0 && array.length() > 0) {
try { try {
JSONObject proofText = new JSONObject(); JSONObject proofText = new JSONObject();
proofText.put("id", -1); proofText.put("id", -1);

@ -52,6 +52,9 @@ public class MakeChanges<TYPE extends RemoteModel> extends ServerToClientMessage
} }
} }
StringProperty uuidProperty = (StringProperty) NameMaps.serverColumnNameToLocalProperty(table, "uuid");
model.setValue(uuidProperty, uuid);
if (model.getSetValues().size() > 0) { if (model.getSetValues().size() > 0) {
model.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); model.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true);
if (dao.update(RemoteModel.UUID_PROPERTY.eq(uuid), model) <= 0) { // If update doesn't update rows. create a new model if (dao.update(RemoteModel.UUID_PROPERTY.eq(uuid), model) <= 0) { // If update doesn't update rows. create a new model

@ -1,9 +1,10 @@
package com.todoroo.astrid.sync; package com.todoroo.astrid.sync;
import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.ActFmSyncThread.ModelType; import com.todoroo.astrid.actfm.sync.ActFmSyncThread.ModelType;
@ -76,6 +77,32 @@ public class SyncMessageTest extends NewSyncTestCase {
} }
} }
public void testMakeChangesMakesNewTasks() {
try {
JSONObject makeChanges = getMakeChanges();
makeChanges.put("uuid", "1");
ServerToClientMessage message = ServerToClientMessage.instantiateMessage(makeChanges);
message.processMessage();
TodorooCursor<Task> cursor = taskDao.query(Query.select(Task.ID, Task.UUID, Task.TITLE, Task.IMPORTANCE).where(Task.UUID.eq("1")));
try {
assertEquals(1, cursor.getCount());
cursor.moveToFirst();
Task t = new Task(cursor);
assertEquals(MAKE_CHANGES_TITLE, t.getValue(Task.TITLE));
assertEquals(Task.IMPORTANCE_DO_OR_DIE, t.getValue(Task.IMPORTANCE).intValue());
assertEquals("1", t.getValue(Task.UUID));
} finally {
cursor.close();
}
} catch (JSONException e) {
e.printStackTrace();
fail("JSONException");
}
}
public void testMakeChangesToPushedAtValues() { public void testMakeChangesToPushedAtValues() {
try { try {
long date = DateUtilities.now(); long date = DateUtilities.now();

Loading…
Cancel
Save