Auto optimize too many connections

This commit is contained in:
M66B
2020-10-06 11:35:35 +02:00
parent 81105e7055
commit 2f09afedac
3 changed files with 23 additions and 2 deletions

View File

@@ -326,6 +326,9 @@ public interface DaoFolder {
@Query("UPDATE folder SET tbd = 1 WHERE id = :id")
int setFolderTbd(long id);
@Query("UPDATE folder SET poll = :poll, poll_count = 1 WHERE id = :id")
int setFolderPoll(long id, boolean poll);
@Query("UPDATE folder SET poll_count = :count WHERE id = :id")
int setFolderPollCount(long id, int count);

View File

@@ -1578,6 +1578,21 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
" last connected: " + new Date(account.last_connected));
if (errors >= FAST_ERROR_COUNT)
state.setBackoff(FAST_ERROR_BACKOFF * 60);
boolean auto_optimize = prefs.getBoolean("auto_optimize", false);
if (auto_optimize) {
Throwable e = ex;
while (e != null) {
if (ConnectionHelper.isMaxConnections(e.getMessage())) {
for (String ft : new String[]{EntityFolder.TRASH, EntityFolder.JUNK}) {
EntityFolder f = db.folder().getFolderByType(account.id, ft);
if (f != null)
db.folder().setFolderPoll(f.id, true);
}
}
e = e.getCause();
}
}
}
// Report account connection error