mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-26 16:03:18 +00:00
Partition operations by priority
This commit is contained in:
parent
544d4dfd61
commit
08365a7f1d
1 changed files with 72 additions and 58 deletions
|
@ -64,6 +64,7 @@ import java.util.Hashtable;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
import javax.mail.AuthenticationFailedException;
|
||||
|
@ -1111,19 +1112,31 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
@Override
|
||||
public void onChanged(final List<TupleOperationEx> _operations) {
|
||||
List<Long> ops = new ArrayList<>();
|
||||
List<TupleOperationEx> operations = new ArrayList<>();
|
||||
List<TupleOperationEx> submit = new ArrayList<>();
|
||||
for (TupleOperationEx op : _operations) {
|
||||
if (!handling.contains(op.id))
|
||||
operations.add(op);
|
||||
submit.add(op);
|
||||
ops.add(op.id);
|
||||
}
|
||||
handling = ops;
|
||||
|
||||
if (operations.size() > 0 ) {
|
||||
Log.i(folder.name + " queuing operations=" + operations.size() +
|
||||
if (submit.size() > 0) {
|
||||
Log.i(folder.name + " queuing operations=" + submit.size() +
|
||||
" init=" + folder.initialize + " poll=" + folder.poll);
|
||||
|
||||
executor.submit(new Helper.PriorityRunnable(operations.get(0).priority) {
|
||||
// Partition operations by priority
|
||||
Map<Integer, List<TupleOperationEx>> partitions = new TreeMap<>();
|
||||
for (TupleOperationEx op : submit) {
|
||||
if (!partitions.containsKey(op.priority))
|
||||
partitions.put(op.priority, new ArrayList<>());
|
||||
partitions.get(op.priority).add(op);
|
||||
}
|
||||
|
||||
for (int priority : partitions.keySet()) {
|
||||
List<TupleOperationEx> partition = partitions.get(priority);
|
||||
Log.i(folder.name + " queuing operations=" + partition.size() + " priority=" + priority);
|
||||
|
||||
executor.submit(new Helper.PriorityRunnable(priority) {
|
||||
@Override
|
||||
public void run() {
|
||||
super.run();
|
||||
|
@ -1156,7 +1169,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
|
||||
Core.processOperations(ServiceSynchronize.this,
|
||||
account, folder,
|
||||
operations,
|
||||
partition,
|
||||
iservice.getStore(), ifolder,
|
||||
state);
|
||||
|
||||
|
@ -1193,6 +1206,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue