Prevent duplicate operation execution

pull/147/head
M66B 6 years ago
parent 7ddcc119e6
commit cdb84c72b3

@ -44,7 +44,7 @@ public interface DaoOperation {
", id") ", id")
LiveData<List<TupleOperationEx>> liveOperations(); LiveData<List<TupleOperationEx>> liveOperations();
@Query("SELECT operation.* FROM operation" + String GET_OPS_FOLDER = "SELECT operation.* FROM operation" +
" JOIN folder ON folder.id = operation.folder" + " JOIN folder ON folder.id = operation.folder" +
" LEFT JOIN message ON message.id = operation.message" + " LEFT JOIN message ON message.id = operation.message" +
" LEFT JOIN account ON account.id = message.account" + " LEFT JOIN account ON account.id = message.account" +
@ -57,7 +57,12 @@ public interface DaoOperation {
" CASE WHEN folder.account IS NULL THEN -1 ELSE 1 END" + // outbox " CASE WHEN folder.account IS NULL THEN -1 ELSE 1 END" + // outbox
" ELSE 0" + " ELSE 0" +
" END" + " END" +
", id") ", id";
@Query(GET_OPS_FOLDER)
List<EntityOperation> getOperations(long folder);
@Query(GET_OPS_FOLDER)
LiveData<List<EntityOperation>> liveOperations(long folder); LiveData<List<EntityOperation>> liveOperations(long folder);
@Query("SELECT * FROM operation ORDER BY id") @Query("SELECT * FROM operation ORDER BY id")

@ -1229,7 +1229,7 @@ public class ServiceSynchronize extends LifecycleService {
db.folder().setFolderError(folder.id, null); db.folder().setFolderError(folder.id, null);
} }
processOperations(account, folder, operations, isession, istore, ifolder, state); processOperations(account, folder, isession, istore, ifolder, state);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(folder.name, ex); Log.e(folder.name, ex);
@ -1433,13 +1433,15 @@ public class ServiceSynchronize extends LifecycleService {
} }
private void processOperations( private void processOperations(
EntityAccount account, EntityFolder folder, List<EntityOperation> ops, Session isession, EntityAccount account, EntityFolder folder,
IMAPStore istore, IMAPFolder ifolder, ServiceState state) Session isession, IMAPStore istore, IMAPFolder ifolder,
ServiceState state)
throws MessagingException, JSONException, IOException { throws MessagingException, JSONException, IOException {
try { try {
Log.i(folder.name + " start process"); Log.i(folder.name + " start process");
DB db = DB.getInstance(this); DB db = DB.getInstance(this);
List<EntityOperation> ops = db.operation().getOperations(folder.id);
Log.i(folder.name + " pending operations=" + ops.size()); Log.i(folder.name + " pending operations=" + ops.size());
for (int i = 0; i < ops.size() && state.running(); i++) { for (int i = 0; i < ops.size() && state.running(); i++) {
EntityOperation op = ops.get(i); EntityOperation op = ops.get(i);
@ -3023,7 +3025,7 @@ public class ServiceSynchronize extends LifecycleService {
Log.i(outbox.name + " process"); Log.i(outbox.name + " process");
db.folder().setFolderSyncState(outbox.id, "syncing"); db.folder().setFolderSyncState(outbox.id, "syncing");
processOperations(null, outbox, operations, null, null, null, state); processOperations(null, outbox, null, null, null, state);
db.folder().setFolderError(outbox.id, null); db.folder().setFolderError(outbox.id, null);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(outbox.name, ex); Log.e(outbox.name, ex);

Loading…
Cancel
Save