Refactoring

pull/210/head
M66B 2 years ago
parent 49e438419d
commit b43515d386

@ -97,7 +97,7 @@ public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.View
StringBuilder sb = new StringBuilder();
sb
.append(operation.name).append(':')
.append(operation.priority).append("/")
.append(operation.getPriority(false)).append("/")
.append(operation.tries);
try {
JSONArray jarray = new JSONArray(operation.args);

@ -54,7 +54,8 @@ public interface DaoOperation {
@Transaction
@Query("SELECT operation.*" +
", " + priority + " AS priority" +
", account.name AS accountName, folder.name AS folderName" +
", account.name AS accountName" +
", folder.name AS folderName, folder.type AS folderType" +
", (account.synchronize IS NULL OR account.synchronize) AS synchronize" +
" FROM operation" +
" JOIN folder ON folder.id = operation.folder" +
@ -65,7 +66,8 @@ public interface DaoOperation {
@Transaction
@Query("SELECT operation.*" +
", " + priority + " AS priority" +
", account.name AS accountName, folder.name AS folderName" +
", account.name AS accountName" +
", folder.name AS folderName, folder.type AS folderType" +
", account.synchronize" +
" FROM operation" +
" JOIN folder ON folder.id = operation.folder" +

@ -2114,7 +2114,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
List<TupleOperationEx.PartitionKey> keys = new ArrayList<>();
synchronized (partitions) {
for (TupleOperationEx op : added.get(folder.id)) {
TupleOperationEx.PartitionKey key = op.getPartitionKey(offline, folder.type);
TupleOperationEx.PartitionKey key = op.getPartitionKey(offline);
if (!partitions.containsKey(key)) {
partitions.put(key, new ArrayList<>());

@ -30,6 +30,7 @@ public class TupleOperationEx extends EntityOperation {
public int priority;
public String accountName;
public String folderName;
public String folderType;
public boolean synchronize;
@Override
@ -40,26 +41,33 @@ public class TupleOperationEx extends EntityOperation {
this.priority == other.priority &&
Objects.equals(this.accountName, other.accountName) &&
Objects.equals(this.folderName, other.folderName) &&
Objects.equals(this.folderType, other.folderType) &&
this.synchronize == other.synchronize);
} else
return false;
}
PartitionKey getPartitionKey(boolean offline, String folderType) {
int getPriority(boolean offline) {
int priority = this.priority;
if (offline)
priority += 20; // connect folder is expensive
if (!EntityFolder.INBOX.equals(folderType)) // prioritize inbox
priority += 10;
return priority;
}
PartitionKey getPartitionKey(boolean offline) {
PartitionKey key = new PartitionKey();
key.folder = this.folder;
key.order = this.id;
key.priority = this.getPriority(offline);
if (offline) {
// open/close folder is expensive
key.priority = this.priority + 20;
if (offline)
return key;
}
key.priority = this.priority;
if (!EntityFolder.INBOX.equals(folderType))
key.priority += 10;
if (ADD.equals(name) ||
DELETE.equals(name))

Loading…
Cancel
Save