Improved autosync logic to be independent of server time

pull/14/head
Sam Bosley 11 years ago
parent 570d340eaf
commit d8cf2f6264

@ -146,6 +146,10 @@ public final class TagData extends RemoteModel {
public static final IntegerProperty HISTORY_HAS_MORE = new IntegerProperty(
TABLE, "historyHasMore");
/** Last autosync */
public static final LongProperty LAST_AUTOSYNC = new LongProperty(
TABLE, "lastAutosync");
/** List of all properties for this model */
public static final Property<?>[] PROPERTIES = generateProperties(TagData.class);
@ -180,6 +184,7 @@ public final class TagData extends RemoteModel {
defaultValues.put(DELETION_DATE.name, 0);
defaultValues.put(HISTORY_FETCH_DATE.name, 0);
defaultValues.put(HISTORY_HAS_MORE.name, 0);
defaultValues.put(LAST_AUTOSYNC.name, 0);
defaultValues.put(THUMB.name, "");
defaultValues.put(LAST_ACTIVITY_DATE.name, 0);

@ -78,6 +78,10 @@ public final class User extends RemoteModel {
public static final StringProperty STATUS = new StringProperty(
TABLE, "status");
/** Last autosync */
public static final LongProperty LAST_AUTOSYNC = new LongProperty(
TABLE, "lastAutosync");
/** Friendship tatus that needs to be reported to the server.
* One of the PENDING constants below */
@Deprecated public static final StringProperty PENDING_STATUS = new StringProperty(
@ -101,6 +105,7 @@ public final class User extends RemoteModel {
defaultValues.put(TASKS_PUSHED_AT.name, 0L);
defaultValues.put(UUID.name, NO_UUID);
defaultValues.put(STATUS.name, "");
defaultValues.put(LAST_AUTOSYNC.name, 0L);
}
@Override

@ -339,9 +339,12 @@ public class TagViewFragment extends TaskListFragment {
if (!isCurrentTaskListFragment())
return;
if (tagData != null) {
long pushedAt = tagData.getValue(TagData.TASKS_PUSHED_AT);
if(DateUtilities.now() - pushedAt > AUTOSYNC_INTERVAL)
long lastAutosync = tagData.getValue(TagData.LAST_AUTOSYNC);
if(DateUtilities.now() - lastAutosync > AUTOSYNC_INTERVAL) {
tagData.setValue(TagData.LAST_AUTOSYNC, DateUtilities.now());
tagDataDao.saveExisting(tagData);
refreshData();
}
}
}

@ -190,12 +190,13 @@ public class PersonViewFragment extends TaskListFragment {
if (!isCurrentTaskListFragment())
return;
if (user != null) {
long pushedAt = user.getValue(User.PUSHED_AT);
long tasksPushedAt = user.getValue(User.TASKS_PUSHED_AT);
long lastAutosync = user.getValue(User.LAST_AUTOSYNC);
if((DateUtilities.now() - pushedAt > AUTOSYNC_INTERVAL) ||
(DateUtilities.now() - tasksPushedAt > AUTOSYNC_INTERVAL))
if(DateUtilities.now() - lastAutosync > AUTOSYNC_INTERVAL) {
refreshData();
user.setValue(User.LAST_AUTOSYNC, DateUtilities.now());
userDao.saveExisting(user);
}
}
}

@ -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 = 33;
public static final int VERSION = 34;
/**
* Database name (must be unique)
@ -395,6 +395,9 @@ public class Database extends AbstractDatabase {
tryExecSQL("DROP TABLE " + History.TABLE.name);
tryExecSQL(createTableSql(visitor, History.TABLE.name, History.PROPERTIES));
tryExecSQL(addColumnSql(User.TABLE, User.TASKS_PUSHED_AT, visitor, null));
case 33:
tryExecSQL(addColumnSql(TagData.TABLE, TagData.LAST_AUTOSYNC, visitor, null));
tryExecSQL(addColumnSql(User.TABLE, User.LAST_AUTOSYNC, visitor, null));
return true;
}

@ -30,7 +30,6 @@ import com.todoroo.andlib.service.ExceptionService;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.actfm.sync.messages.NameMaps;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.SyncAction;
@ -88,7 +87,7 @@ public class SyncActionHelper {
// --- automatic sync logic
public void initiateAutomaticSync() {
long tasksPushedAt = Preferences.getLong(NameMaps.PUSHED_AT_TASKS, 0);
long tasksPushedAt = Preferences.getLong(PREF_LAST_AUTO_SYNC, 0);
if (DateUtilities.now() - tasksPushedAt > TaskListFragment.AUTOSYNC_INTERVAL) {
performSyncServiceV2Sync(false);
}

Loading…
Cancel
Save