Process newly arrived operations only

This commit is contained in:
M66B 2019-01-29 14:54:49 +00:00
parent 53c1b31f41
commit cb1ded8ecf
1 changed files with 33 additions and 22 deletions

View File

@ -1189,18 +1189,19 @@ public class ServiceSynchronize extends LifecycleService {
PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":folder." + folder.id); PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":folder." + folder.id);
@Override @Override
public void onChanged(final List<EntityOperation> operations) { public void onChanged(final List<EntityOperation> ops) {
boolean process = false; final List<EntityOperation> arrived = new ArrayList<>();
List<Long> current = new ArrayList<>(); synchronized (handling) {
for (EntityOperation op : operations) { for (EntityOperation op : ops) {
if (!handling.contains(op.id)) if (!handling.contains(op.id)) {
process = true; handling.add(op.id);
current.add(op.id); arrived.add(op);
}
}
} }
handling = current;
if (handling.size() > 0 && process) { if (arrived.size() > 0) {
Log.i(folder.name + " operations=" + operations.size()); Log.i(folder.name + " process operations=" + arrived.size());
(folder.poll ? pollExecutor : folderExecutor).submit(new Runnable() { (folder.poll ? pollExecutor : folderExecutor).submit(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1229,8 +1230,12 @@ public class ServiceSynchronize extends LifecycleService {
db.folder().setFolderError(folder.id, null); db.folder().setFolderError(folder.id, null);
} }
processOperations(account, folder, operations, isession, istore, ifolder, state); processOperations(account, folder, arrived, isession, istore, ifolder, state);
synchronized (handling) {
for (EntityOperation op : arrived)
handling.remove(op.id);
}
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(folder.name, ex); Log.e(folder.name, ex);
reportError(account, folder, ex); reportError(account, folder, ex);
@ -3003,18 +3008,19 @@ public class ServiceSynchronize extends LifecycleService {
PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":outbox"); PowerManager.PARTIAL_WAKE_LOCK, BuildConfig.APPLICATION_ID + ":outbox");
@Override @Override
public void onChanged(final List<EntityOperation> operations) { public void onChanged(final List<EntityOperation> ops) {
boolean process = false; final List<EntityOperation> arrived = new ArrayList<>();
List<Long> current = new ArrayList<>(); synchronized (handling) {
for (EntityOperation op : operations) { for (EntityOperation op : ops) {
if (!handling.contains(op.id)) if (!handling.contains(op.id)) {
process = true; handling.add(op.id);
current.add(op.id); arrived.add(op);
}
}
} }
handling = current;
if (handling.size() > 0 && process) { if (arrived.size() > 0) {
Log.i(outbox.name + " operations=" + operations.size()); Log.i(outbox.name + " process operations=" + arrived.size());
executor.submit(new Runnable() { executor.submit(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -3023,8 +3029,13 @@ public class ServiceSynchronize extends LifecycleService {
Log.i(outbox.name + " process"); Log.i(outbox.name + " process");
db.folder().setFolderSyncState(outbox.id, "syncing"); db.folder().setFolderSyncState(outbox.id, "syncing");
processOperations(null, outbox, operations, null, null, null, state); processOperations(null, outbox, arrived, null, null, null, state);
db.folder().setFolderError(outbox.id, null); db.folder().setFolderError(outbox.id, null);
for (EntityOperation op : arrived)
synchronized (handling) {
handling.remove(op.id);
}
} catch (Throwable ex) { } catch (Throwable ex) {
Log.e(outbox.name, ex); Log.e(outbox.name, ex);
reportError(null, outbox, ex); reportError(null, outbox, ex);