mirror of https://github.com/M66B/FairEmail.git
Guarantee poll
This commit is contained in:
parent
7962afc2e6
commit
147290953d
|
@ -103,6 +103,9 @@ public interface DaoOperation {
|
|||
@Query("SELECT * FROM operation WHERE account = :account AND name = :name")
|
||||
List<EntityOperation> getOperations(long account, String name);
|
||||
|
||||
@Query("SELECT * FROM operation WHERE folder = :folder AND name = :name")
|
||||
List<EntityOperation> getOperationsByFolder(long folder, String name);
|
||||
|
||||
@Query("SELECT * FROM operation WHERE id = :id")
|
||||
EntityOperation getOperation(long id);
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ package eu.faircode.email;
|
|||
Copyright 2018-2021 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import static androidx.room.ForeignKey.CASCADE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.text.TextUtils;
|
||||
|
@ -44,8 +46,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static androidx.room.ForeignKey.CASCADE;
|
||||
|
||||
@Entity(
|
||||
tableName = EntityOperation.TABLE_NAME,
|
||||
foreignKeys = {
|
||||
|
@ -425,6 +425,22 @@ public class EntityOperation {
|
|||
Log.breadcrumb("queued", crumb);
|
||||
}
|
||||
|
||||
static void poll(Context context, long fid) throws JSONException {
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
boolean force = false;
|
||||
List<EntityOperation> ops = db.operation().getOperationsByFolder(fid, EntityOperation.SYNC);
|
||||
if (ops != null)
|
||||
for (EntityOperation op : ops)
|
||||
if (EntityFolder.isSyncForced(op.args)) {
|
||||
force = true;
|
||||
break;
|
||||
}
|
||||
|
||||
db.operation().deleteOperation(fid, EntityOperation.SYNC);
|
||||
sync(context, fid, false, force);
|
||||
}
|
||||
|
||||
static void sync(Context context, long fid, boolean foreground) {
|
||||
sync(context, fid, foreground, false);
|
||||
}
|
||||
|
|
|
@ -1075,7 +1075,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
if (folders.size() > 0)
|
||||
Collections.sort(folders, folders.get(0).getComparator(ServiceSynchronize.this));
|
||||
for (EntityFolder folder : folders)
|
||||
EntityOperation.sync(ServiceSynchronize.this, folder.id, false);
|
||||
EntityOperation.poll(ServiceSynchronize.this, folder.id);
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
|
@ -1906,18 +1906,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
throw new StoreClosedException(iservice.getStore(), "NOOP " + folder.name);
|
||||
} else {
|
||||
if (folder.poll_count == 0) {
|
||||
// Cancel pending sync, for example when the folder is not set to poll
|
||||
boolean fforce = false;
|
||||
List<EntityOperation> ops = db.operation().getOperations(folder.account, EntityOperation.SYNC);
|
||||
for (EntityOperation op : ops)
|
||||
if (EntityFolder.isSyncForced(op.args)) {
|
||||
fforce = true;
|
||||
break;
|
||||
}
|
||||
db.operation().deleteOperation(folder.id, EntityOperation.SYNC);
|
||||
|
||||
EntityLog.log(this, folder.name + " queue sync poll");
|
||||
EntityOperation.sync(this, folder.id, false, fforce);
|
||||
EntityOperation.poll(this, folder.id);
|
||||
}
|
||||
folder.poll_count = (folder.poll_count + 1) % folder.poll_factor;
|
||||
db.folder().setFolderPollCount(folder.id, folder.poll_count);
|
||||
|
|
Loading…
Reference in New Issue