Auto force on repeated manual sync

pull/194/merge
M66B 4 years ago
parent b019d17c06
commit d1600ad188

File diff suppressed because it is too large Load Diff

@ -68,7 +68,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 216, version = 217,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -2201,6 +2201,12 @@ public abstract class DB extends RoomDatabase {
Log.i("DB migration from version " + startVersion + " to " + endVersion); Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `infrastructure` TEXT"); db.execSQL("ALTER TABLE `message` ADD COLUMN `infrastructure` TEXT");
} }
}).addMigrations(new Migration(216, 217) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `folder` ADD COLUMN `last_sync_foreground` INTEGER");
}
}).addMigrations(new Migration(998, 999) { }).addMigrations(new Migration(998, 999) {
@Override @Override
public void migrate(@NonNull SupportSQLiteDatabase db) { public void migrate(@NonNull SupportSQLiteDatabase db) {

@ -350,6 +350,9 @@ public interface DaoFolder {
@Query("UPDATE folder SET last_sync = :last_sync WHERE id = :id AND NOT (last_sync IS :last_sync)") @Query("UPDATE folder SET last_sync = :last_sync WHERE id = :id AND NOT (last_sync IS :last_sync)")
int setFolderLastSync(long id, long last_sync); int setFolderLastSync(long id, long last_sync);
@Query("UPDATE folder SET last_sync_foreground = :last_sync_foreground WHERE id = :id AND NOT (last_sync_foreground IS :last_sync_foreground)")
int setFolderLastSyncForeground(long id, long last_sync_foreground);
@Query("UPDATE folder SET last_sync_count = :last_sync_count WHERE id = :id AND NOT (last_sync_count IS :last_sync_count)") @Query("UPDATE folder SET last_sync_count = :last_sync_count WHERE id = :id AND NOT (last_sync_count IS :last_sync_count)")
int setFolderLastSyncCount(long id, Integer last_sync_count); int setFolderLastSyncCount(long id, Integer last_sync_count);

@ -139,6 +139,7 @@ public class EntityFolder extends EntityOrder implements Serializable {
public Boolean inferiors = true; public Boolean inferiors = true;
public String error; public String error;
public Long last_sync; public Long last_sync;
public Long last_sync_foreground;
public Integer last_sync_count; // POP3 public Integer last_sync_count; // POP3
static final String INBOX = "Inbox"; static final String INBOX = "Inbox";

@ -103,6 +103,7 @@ public class EntityOperation {
static final String EXPUNGE = "expunge"; static final String EXPUNGE = "expunge";
private static final int MAX_FETCH = 100; // operations private static final int MAX_FETCH = 100; // operations
private static final long FORCE_WITHIN = 30 * 1000; // milliseconds
static void queue(Context context, EntityMessage message, String name, Object... values) { static void queue(Context context, EntityMessage message, String name, Object... values) {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -494,6 +495,16 @@ public class EntityOperation {
if (folder == null) if (folder == null)
return; return;
if (foreground) {
long now = new Date().getTime();
if (folder.last_sync_foreground != null &&
now - folder.last_sync_foreground < FORCE_WITHIN) {
Log.i(folder.name + " Auto force");
force = true;
}
db.folder().setFolderLastSyncForeground(folder.id, now);
}
if (force) if (force)
db.operation().deleteOperation(fid, SYNC); db.operation().deleteOperation(fid, SYNC);
@ -508,7 +519,7 @@ public class EntityOperation {
operation.created = new Date().getTime(); operation.created = new Date().getTime();
operation.id = db.operation().insertOperation(operation); operation.id = db.operation().insertOperation(operation);
Log.i("Queued sync folder=" + folder); Log.i("Queued sync folder=" + folder + " force=" + force);
} }
if (foreground && folder.sync_state == null) // Show spinner if (foreground && folder.sync_state == null) // Show spinner

Loading…
Cancel
Save