mirror of https://github.com/M66B/FairEmail.git
Process while running and recoverable
This commit is contained in:
parent
482aec8eb0
commit
1c6831d6d9
|
@ -115,7 +115,7 @@ class Core {
|
||||||
DB db = DB.getInstance(context);
|
DB db = DB.getInstance(context);
|
||||||
List<EntityOperation> ops = db.operation().getOperations(folder.id);
|
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() && state.recoverable(); i++) {
|
||||||
EntityOperation op = ops.get(i);
|
EntityOperation op = ops.get(i);
|
||||||
try {
|
try {
|
||||||
Log.i(folder.name +
|
Log.i(folder.name +
|
||||||
|
@ -874,7 +874,7 @@ class Core {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (int i = 0; i < imessages.length && state.running(); i++)
|
for (int i = 0; i < imessages.length && state.running() && state.recoverable(); i++)
|
||||||
try {
|
try {
|
||||||
uids.remove(ifolder.getUID(imessages[i]));
|
uids.remove(ifolder.getUID(imessages[i]));
|
||||||
} catch (MessageRemovedException ex) {
|
} catch (MessageRemovedException ex) {
|
||||||
|
@ -938,14 +938,14 @@ class Core {
|
||||||
// Add/update local messages
|
// Add/update local messages
|
||||||
Long[] ids = new Long[imessages.length];
|
Long[] ids = new Long[imessages.length];
|
||||||
Log.i(folder.name + " add=" + imessages.length);
|
Log.i(folder.name + " add=" + imessages.length);
|
||||||
for (int i = imessages.length - 1; i >= 0 && state.running(); i -= SYNC_BATCH_SIZE) {
|
for (int i = imessages.length - 1; i >= 0 && state.running() && state.recoverable(); i -= SYNC_BATCH_SIZE) {
|
||||||
int from = Math.max(0, i - SYNC_BATCH_SIZE + 1);
|
int from = Math.max(0, i - SYNC_BATCH_SIZE + 1);
|
||||||
Message[] isub = Arrays.copyOfRange(imessages, from, i + 1);
|
Message[] isub = Arrays.copyOfRange(imessages, from, i + 1);
|
||||||
|
|
||||||
// Full fetch new/changed messages only
|
// Full fetch new/changed messages only
|
||||||
List<Message> full = new ArrayList<>();
|
List<Message> full = new ArrayList<>();
|
||||||
for (Message imessage : isub) {
|
for (Message imessage : isub) {
|
||||||
long uid = ifolder.getUID(imessage);
|
long uid = ifolder.getUID(imessage); // already fetched
|
||||||
EntityMessage message = db.message().getMessageByUid(folder.id, uid);
|
EntityMessage message = db.message().getMessageByUid(folder.id, uid);
|
||||||
if (message == null)
|
if (message == null)
|
||||||
full.add(imessage);
|
full.add(imessage);
|
||||||
|
@ -957,7 +957,7 @@ class Core {
|
||||||
" " + (SystemClock.elapsedRealtime() - headers) + " ms");
|
" " + (SystemClock.elapsedRealtime() - headers) + " ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = isub.length - 1; j >= 0 && state.running(); j--)
|
for (int j = isub.length - 1; j >= 0 && state.running() && state.recoverable(); j--)
|
||||||
try {
|
try {
|
||||||
EntityMessage message = synchronizeMessage(
|
EntityMessage message = synchronizeMessage(
|
||||||
context,
|
context,
|
||||||
|
@ -1010,13 +1010,13 @@ class Core {
|
||||||
|
|
||||||
// Download messages/attachments
|
// Download messages/attachments
|
||||||
Log.i(folder.name + " download=" + imessages.length);
|
Log.i(folder.name + " download=" + imessages.length);
|
||||||
for (int i = imessages.length - 1; i >= 0 && state.running(); i -= DOWNLOAD_BATCH_SIZE) {
|
for (int i = imessages.length - 1; i >= 0 && state.running() && state.recoverable(); i -= DOWNLOAD_BATCH_SIZE) {
|
||||||
int from = Math.max(0, i - DOWNLOAD_BATCH_SIZE + 1);
|
int from = Math.max(0, i - DOWNLOAD_BATCH_SIZE + 1);
|
||||||
|
|
||||||
Message[] isub = Arrays.copyOfRange(imessages, from, i + 1);
|
Message[] isub = Arrays.copyOfRange(imessages, from, i + 1);
|
||||||
// Fetch on demand
|
// Fetch on demand
|
||||||
|
|
||||||
for (int j = isub.length - 1; j >= 0 && state.running(); j--)
|
for (int j = isub.length - 1; j >= 0 && state.running() && state.recoverable(); j--)
|
||||||
try {
|
try {
|
||||||
if (ids[from + j] != null)
|
if (ids[from + j] != null)
|
||||||
downloadMessage(
|
downloadMessage(
|
||||||
|
|
|
@ -823,7 +823,7 @@ public class ServiceSynchronize extends LifecycleService {
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Log.i(folder.name + " start idle");
|
Log.i(folder.name + " start idle");
|
||||||
while (state.running()) {
|
while (state.running() && state.recoverable()) {
|
||||||
Log.i(folder.name + " do idle");
|
Log.i(folder.name + " do idle");
|
||||||
ifolder.idle(false);
|
ifolder.idle(false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue