Reduced operation processing

This commit is contained in:
M66B 2020-11-06 09:25:00 +01:00
parent 75480a6f42
commit 074a2d953e
1 changed files with 21 additions and 17 deletions

View File

@ -1295,27 +1295,31 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
@Override
public void onChanged(final List<TupleOperationEx> _operations) {
// Get new operations
List<Long> ops = new ArrayList<>();
Map<EntityFolder, List<TupleOperationEx>> added = new HashMap<>();
List<Long> all = new ArrayList<>();
Map<Long, List<TupleOperationEx>> added = new HashMap<>();
for (TupleOperationEx op : _operations) {
all.add(op.id);
if (!handling.contains(op.id)) {
boolean found = false;
for (EntityFolder folder : mapFolders.keySet())
if (Objects.equals(folder.id, op.folder)) {
found = true;
if (!added.containsKey(folder))
added.put(folder, new ArrayList<>());
added.get(folder).add(op);
if (!added.containsKey(op.folder))
added.put(op.folder, new ArrayList<>());
added.get(op.folder).add(op);
}
}
handling = all;
for (Long fid : added.keySet()) {
EntityFolder found = null;
for (EntityFolder f : mapFolders.keySet())
if (Objects.equals(fid, f.id)) {
found = f;
break;
}
if (!found)
Log.w(account.name + " folder not found operation=" + op.name);
if (found == null) {
Log.w(account.name + " folder not found operation=" + fid);
continue;
}
ops.add(op.id);
}
handling = ops;
for (EntityFolder folder : added.keySet()) {
final EntityFolder folder = found;
Log.i(folder.name + " queuing operations=" + added.size() +
" init=" + folder.initialize + " poll=" + folder.poll);
@ -1323,7 +1327,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
boolean offline = (mapFolders.get(folder) == null);
List<TupleOperationEx.PartitionKey> keys = new ArrayList<>();
synchronized (partitions) {
for (TupleOperationEx op : added.get(folder)) {
for (TupleOperationEx op : added.get(folder.id)) {
TupleOperationEx.PartitionKey key = op.getPartitionKey(offline);
if (!partitions.containsKey(key)) {