Skip redundant operations

pull/162/head
M66B 5 years ago
parent 012b6d1e7f
commit 1982c72f03

@ -177,11 +177,32 @@ class Core {
// Operations should use database transaction when needed
// Squash operations
if (i + 1 < ops.size() && op.canSquash(ops.get(i + 1))) {
// Skip redundant operations
boolean skip = false;
for (int j = i + 1; j < ops.size(); j++) {
EntityOperation next = ops.get(j);
if (EntityOperation.ADD.equals(op.name)) {
if (Objects.equals(op.message, next.message) &&
(EntityOperation.ADD.equals(next.name) ||
EntityOperation.DELETE.equals(next.name))) {
skip = true;
break;
}
} else if (EntityOperation.FETCH.equals(op.name))
if (EntityOperation.FETCH.equals(next.name)) {
JSONArray jnext = new JSONArray(next.args);
if (jargs.getLong(0) == jnext.getLong(0)) {
skip = true;
break;
}
}
}
if (skip) {
Log.i(folder.name +
" squashing op=" + op.id + "/" + op.name +
" skipping op=" + op.id + "/" + op.name +
" msg=" + op.message + " args=" + op.args);
db.operation().deleteOperation(op.id);
continue;
}

@ -341,21 +341,6 @@ public class EntityOperation {
Log.i("Queued subscribe=" + subscribe + " folder=" + folder);
}
boolean canSquash(EntityOperation next) throws JSONException {
if (Objects.equals(this.message, next.message) &&
ADD.equals(this.name) &&
(ADD.equals(next.name) || DELETE.equals(next.name)))
return true;
if (FETCH.equals(this.name) && FETCH.equals(next.name)) {
JSONArray jargs1 = new JSONArray(this.args);
JSONArray jargs2 = new JSONArray(next.args);
return (jargs1.optLong(0, -1) == jargs2.optLong(0, -2));
}
return false;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof EntityOperation) {

Loading…
Cancel
Save