Only enqueue changes happened messages if actual outstanding entries were recording. This could fix a bug where the queue would get filled up with pointless messages

pull/14/head
Sam Bosley 12 years ago
parent 494a8ec371
commit 71a14e78fd

@ -310,10 +310,11 @@ public class DatabaseDao<TYPE extends AbstractModel> {
public void onBegin() {/**/} public void onBegin() {/**/}
}); });
} }
int numOutstanding = 0;
try { try {
result.set(op.makeChange()); result.set(op.makeChange());
if(result.get()) { if(result.get()) {
if (recordOutstanding && createOutstandingEntries(item.getId(), values)) // Create entries for setValues in outstanding table if (recordOutstanding && ((numOutstanding = createOutstandingEntries(item.getId(), values)) != -1)) // Create entries for setValues in outstanding table
database.getDatabase().setTransactionSuccessful(); database.getDatabase().setTransactionSuccessful();
} }
} finally { } finally {
@ -321,7 +322,7 @@ public class DatabaseDao<TYPE extends AbstractModel> {
database.getDatabase().endTransaction(); database.getDatabase().endTransaction();
} }
if (result.get()) { if (result.get()) {
onModelUpdated(item, recordOutstanding); onModelUpdated(item, recordOutstanding && numOutstanding > 0);
item.markSaved(); item.markSaved();
} }
return result.get(); return result.get();
@ -378,27 +379,29 @@ public class DatabaseDao<TYPE extends AbstractModel> {
return insertOrUpdateAndRecordChanges(item, values, update); return insertOrUpdateAndRecordChanges(item, values, update);
} }
protected boolean createOutstandingEntries(long modelId, ContentValues modelSetValues) { protected int createOutstandingEntries(long modelId, ContentValues modelSetValues) {
Set<Entry<String, Object>> entries = modelSetValues.valueSet(); Set<Entry<String, Object>> entries = modelSetValues.valueSet();
long now = DateUtilities.now(); long now = DateUtilities.now();
int count = 0;
for (Entry<String, Object> entry : entries) { for (Entry<String, Object> entry : entries) {
if (entry.getValue() != null && shouldRecordOutstandingEntry(entry.getKey())) { if (entry.getValue() != null && shouldRecordOutstandingEntry(entry.getKey())) {
AbstractModel m; AbstractModel m;
try { try {
m = outstandingTable.modelClass.newInstance(); m = outstandingTable.modelClass.newInstance();
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
return false; return -1;
} catch (InstantiationException e2) { } catch (InstantiationException e2) {
return false; return -1;
} }
m.setValue(OutstandingEntry.ENTITY_ID_PROPERTY, modelId); m.setValue(OutstandingEntry.ENTITY_ID_PROPERTY, modelId);
m.setValue(OutstandingEntry.COLUMN_STRING_PROPERTY, entry.getKey()); m.setValue(OutstandingEntry.COLUMN_STRING_PROPERTY, entry.getKey());
m.setValue(OutstandingEntry.VALUE_STRING_PROPERTY, entry.getValue().toString()); m.setValue(OutstandingEntry.VALUE_STRING_PROPERTY, entry.getValue().toString());
m.setValue(OutstandingEntry.CREATED_AT_PROPERTY, now); m.setValue(OutstandingEntry.CREATED_AT_PROPERTY, now);
database.insert(outstandingTable.name, null, m.getSetValues()); database.insert(outstandingTable.name, null, m.getSetValues());
count++;
} }
} }
return true; return count;
} }
/** /**

@ -8,8 +8,6 @@ package com.todoroo.astrid.data;
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class SyncFlags { public class SyncFlags {
public static final String ACTFM_SUPPRESS_SYNC = "actfm_suppress_sync";
public static final String GTASKS_SUPPRESS_SYNC = "gtasks_suppress_sync"; public static final String GTASKS_SUPPRESS_SYNC = "gtasks_suppress_sync";
public static final String ACTFM_SUPPRESS_OUTSTANDING_ENTRIES = "actfm-suppress-outstanding"; public static final String ACTFM_SUPPRESS_OUTSTANDING_ENTRIES = "actfm-suppress-outstanding";

@ -286,7 +286,6 @@ public class GCMIntentService extends GCMBaseIntentService {
task.setValue(Task.TITLE, intent.getStringExtra("title")); task.setValue(Task.TITLE, intent.getStringExtra("title"));
task.setValue(Task.UUID, intent.getStringExtra("task_id")); task.setValue(Task.UUID, intent.getStringExtra("task_id"));
task.setValue(Task.USER_ID, Task.USER_ID_UNASSIGNED); task.setValue(Task.USER_ID, Task.USER_ID_UNASSIGNED);
task.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
task.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); task.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true);
taskService.save(task); taskService.save(task);
} else { } else {
@ -318,7 +317,6 @@ public class GCMIntentService extends GCMBaseIntentService {
if(cursor.getCount() == 0) { if(cursor.getCount() == 0) {
tagData.setValue(TagData.NAME, intent.getStringExtra("title")); tagData.setValue(TagData.NAME, intent.getStringExtra("title"));
tagData.setValue(TagData.UUID, intent.getStringExtra("tag_id")); tagData.setValue(TagData.UUID, intent.getStringExtra("tag_id"));
tagData.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
tagData.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); tagData.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true);
tagDataService.save(tagData); tagDataService.save(tagData);
} else { } else {

@ -87,12 +87,12 @@ public class MetadataDao extends DatabaseDao<Metadata> {
} }
@Override @Override
protected boolean createOutstandingEntries(long modelId, ContentValues modelSetValues) { protected int createOutstandingEntries(long modelId, ContentValues modelSetValues) {
Long taskId = modelSetValues.getAsLong(Metadata.TASK.name); Long taskId = modelSetValues.getAsLong(Metadata.TASK.name);
String tagUuid = modelSetValues.getAsString(TaskToTagMetadata.TAG_UUID.name); String tagUuid = modelSetValues.getAsString(TaskToTagMetadata.TAG_UUID.name);
Long deletionDate = modelSetValues.getAsLong(Metadata.DELETION_DATE.name); Long deletionDate = modelSetValues.getAsLong(Metadata.DELETION_DATE.name);
if (taskId == null || taskId == AbstractModel.NO_ID || RemoteModel.isUuidEmpty(tagUuid)) if (taskId == null || taskId == AbstractModel.NO_ID || RemoteModel.isUuidEmpty(tagUuid))
return false; return -1;
TaskOutstanding to = new TaskOutstanding(); TaskOutstanding to = new TaskOutstanding();
to.setValue(OutstandingEntry.ENTITY_ID_PROPERTY, taskId); to.setValue(OutstandingEntry.ENTITY_ID_PROPERTY, taskId);
@ -107,7 +107,7 @@ public class MetadataDao extends DatabaseDao<Metadata> {
database.insert(outstandingTable.name, null, to.getSetValues()); database.insert(outstandingTable.name, null, to.getSetValues());
ActFmSyncThread.getInstance().enqueueMessage(new ChangesHappened<Task, TaskOutstanding>(taskId, Task.class, ActFmSyncThread.getInstance().enqueueMessage(new ChangesHappened<Task, TaskOutstanding>(taskId, Task.class,
PluginServices.getTaskDao(), PluginServices.getTaskOutstandingDao()), null); PluginServices.getTaskDao(), PluginServices.getTaskOutstandingDao()), null);
return true; return 1;
} }
@Override @Override

@ -81,12 +81,12 @@ public class TagMetadataDao extends DatabaseDao<TagMetadata> {
} }
@Override @Override
protected boolean createOutstandingEntries(long modelId, ContentValues modelSetValues) { protected int createOutstandingEntries(long modelId, ContentValues modelSetValues) {
Long tagDataId = modelSetValues.getAsLong(TagMetadata.TAG_ID.name); Long tagDataId = modelSetValues.getAsLong(TagMetadata.TAG_ID.name);
String memberId = modelSetValues.getAsString(TagMemberMetadata.USER_UUID.name); String memberId = modelSetValues.getAsString(TagMemberMetadata.USER_UUID.name);
Long deletionDate = modelSetValues.getAsLong(TagMetadata.DELETION_DATE.name); Long deletionDate = modelSetValues.getAsLong(TagMetadata.DELETION_DATE.name);
if (tagDataId == null || tagDataId == AbstractModel.NO_ID || RemoteModel.isUuidEmpty(memberId)) if (tagDataId == null || tagDataId == AbstractModel.NO_ID || RemoteModel.isUuidEmpty(memberId))
return false; return -1;
TagOutstanding to = new TagOutstanding(); TagOutstanding to = new TagOutstanding();
to.setValue(OutstandingEntry.ENTITY_ID_PROPERTY, tagDataId); to.setValue(OutstandingEntry.ENTITY_ID_PROPERTY, tagDataId);
@ -101,7 +101,7 @@ public class TagMetadataDao extends DatabaseDao<TagMetadata> {
database.insert(outstandingTable.name, null, to.getSetValues()); database.insert(outstandingTable.name, null, to.getSetValues());
ActFmSyncThread.getInstance().enqueueMessage(new ChangesHappened<TagData, TagOutstanding>(tagDataId, TagData.class, ActFmSyncThread.getInstance().enqueueMessage(new ChangesHappened<TagData, TagOutstanding>(tagDataId, TagData.class,
PluginServices.getTagDataDao(), PluginServices.getTagOutstandingDao()), null); PluginServices.getTagDataDao(), PluginServices.getTagOutstandingDao()), null);
return true; return 1;
} }
public void createMemberLink(long tagId, String tagUuid, String memberId, boolean suppressOutstanding) { public void createMemberLink(long tagId, String tagUuid, String memberId, boolean suppressOutstanding) {

@ -90,7 +90,7 @@ public class DueDateTimeMigrator {
adjuster.adjust(date); adjuster.adjust(date);
curr.setValue(Task.DUE_DATE, date.getTime()); curr.setValue(Task.DUE_DATE, date.getTime());
curr.getSetValues().put(Task.MODIFICATION_DATE.name, curr.getValue(Task.MODIFICATION_DATE)); // Don't change modification date curr.getSetValues().put(Task.MODIFICATION_DATE.name, curr.getValue(Task.MODIFICATION_DATE)); // Don't change modification date
curr.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true); curr.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true);
curr.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true); curr.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true);
taskDao.save(curr); taskDao.save(curr);
} }

@ -190,7 +190,6 @@ public class TaskService {
try { try {
if(cursor.getCount() > 0) { if(cursor.getCount() > 0) {
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
newTask.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
newTask.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true); newTask.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true);
taskDao.save(newTask); taskDao.save(newTask);
long newId = newTask.getId(); long newId = newTask.getId();

@ -384,7 +384,6 @@ public class QuickAddBar extends LinearLayout {
Uri calendarUri = GCalHelper.createTaskEvent(task, Uri calendarUri = GCalHelper.createTaskEvent(task,
ContextManager.getContext().getContentResolver(), new ContentValues()); ContextManager.getContext().getContentResolver(), new ContentValues());
task.setValue(Task.CALENDAR_URI, calendarUri.toString()); task.setValue(Task.CALENDAR_URI, calendarUri.toString());
task.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
task.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true); task.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true);
PluginServices.getTaskService().save(task); PluginServices.getTaskService().save(task);
} }

Loading…
Cancel
Save