mirror of https://github.com/M66B/FairEmail.git
Partition by fetch/uid
This commit is contained in:
parent
8d73342363
commit
7183255de8
|
@ -22,6 +22,8 @@ package eu.faircode.email;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class TupleOperationEx extends EntityOperation {
|
public class TupleOperationEx extends EntityOperation {
|
||||||
|
@ -45,20 +47,30 @@ public class TupleOperationEx extends EntityOperation {
|
||||||
|
|
||||||
PartitionKey getPartitionKey(boolean offline) {
|
PartitionKey getPartitionKey(boolean offline) {
|
||||||
PartitionKey key = new PartitionKey();
|
PartitionKey key = new PartitionKey();
|
||||||
|
|
||||||
|
if (FETCH.equals(name))
|
||||||
|
try {
|
||||||
|
JSONArray jargs = new JSONArray(args);
|
||||||
|
long uid = jargs.getLong(0);
|
||||||
|
key.id = "uid:" + uid;
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
Log.e(ex);
|
||||||
|
}
|
||||||
|
else if (!MOVE.equals(name))
|
||||||
|
key.id = "id:" + id;
|
||||||
|
|
||||||
|
key.priority = this.priority;
|
||||||
|
key.operation = this.name;
|
||||||
|
|
||||||
if (offline)
|
if (offline)
|
||||||
key.priority = this.priority + 10;
|
key.priority += 10;
|
||||||
else {
|
|
||||||
key.id = (MOVE.equals(name) || FETCH.equals(name) ? 0 : this.id);
|
|
||||||
key.priority = this.priority;
|
|
||||||
key.operation = this.name;
|
|
||||||
}
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PartitionKey {
|
class PartitionKey {
|
||||||
private long id;
|
private String id;
|
||||||
private int priority;
|
private int priority;
|
||||||
@NonNull
|
|
||||||
private String operation;
|
private String operation;
|
||||||
|
|
||||||
int getPriority() {
|
int getPriority() {
|
||||||
|
@ -74,7 +86,7 @@ public class TupleOperationEx extends EntityOperation {
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (obj instanceof PartitionKey) {
|
if (obj instanceof PartitionKey) {
|
||||||
PartitionKey other = (PartitionKey) obj;
|
PartitionKey other = (PartitionKey) obj;
|
||||||
return (this.id == other.id &&
|
return (Objects.equals(this.id, other.id) &&
|
||||||
this.priority == other.priority &&
|
this.priority == other.priority &&
|
||||||
Objects.equals(this.operation, other.operation));
|
Objects.equals(this.operation, other.operation));
|
||||||
} else
|
} else
|
||||||
|
@ -84,7 +96,9 @@ public class TupleOperationEx extends EntityOperation {
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return operation + ":" + priority + ":" + id;
|
return (id == null ? "" : id) + ":" +
|
||||||
|
priority + ":" +
|
||||||
|
(operation == null ? "" : operation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue