One swallow does not make a summer

pull/178/head
M66B 5 years ago
parent d878f76170
commit 4004f07e08

File diff suppressed because it is too large Load Diff

@ -182,7 +182,8 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
(BuildConfig.DEBUG ? (BuildConfig.DEBUG ?
" " + account.poll_interval + " " + account.poll_interval +
"/" + account.keep_alive_ok + "/" + account.keep_alive_ok +
"/" + account.keep_alive_failed : ""))); "/" + account.keep_alive_failed +
"/" + account.keep_alive_succeeded : "")));
tvQuota.setText(context.getString(R.string.title_storage_quota, tvQuota.setText(context.getString(R.string.title_storage_quota,
(account.quota_usage == null ? "-" : Helper.humanReadableByteCount(account.quota_usage, true)), (account.quota_usage == null ? "-" : Helper.humanReadableByteCount(account.quota_usage, true)),
(account.quota_limit == null ? "-" : Helper.humanReadableByteCount(account.quota_limit, true)))); (account.quota_limit == null ? "-" : Helper.humanReadableByteCount(account.quota_limit, true))));

@ -60,7 +60,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
// https://developer.android.com/topic/libraries/architecture/room.html // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 150, version = 151,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -1429,6 +1429,13 @@ public abstract class DB extends RoomDatabase {
Log.i("DB migration from version " + startVersion + " to " + endVersion); Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `language` TEXT"); db.execSQL("ALTER TABLE `message` ADD COLUMN `language` TEXT");
} }
})
.addMigrations(new Migration(150, 151) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `keep_alive_succeeded` INTEGER NOT NULL DEFAULT 0");
}
}); });
} }

@ -149,8 +149,10 @@ public interface DaoAccount {
@Query("UPDATE account SET keep_alive_ok = :ok WHERE id = :id") @Query("UPDATE account SET keep_alive_ok = :ok WHERE id = :id")
int setAccountKeepAliveOk(long id, boolean ok); int setAccountKeepAliveOk(long id, boolean ok);
@Query("UPDATE account SET keep_alive_failed = :value WHERE id = :id") @Query("UPDATE account" +
int setAccountKeepAliveFailed(long id, int value); " SET keep_alive_failed = :failed, keep_alive_succeeded = :succeeded" +
" WHERE id = :id")
int setAccountKeepAliveValues(long id, int failed, int succeeded);
@Query("UPDATE account SET poll_exempted = :value WHERE id = :id") @Query("UPDATE account SET poll_exempted = :value WHERE id = :id")
int setAccountPollExempted(long id, boolean value); int setAccountPollExempted(long id, boolean value);

@ -119,6 +119,8 @@ public class EntityAccount extends EntityOrder implements Serializable {
@NonNull @NonNull
public Integer keep_alive_failed = 0; public Integer keep_alive_failed = 0;
@NonNull @NonNull
public Integer keep_alive_succeeded = 0;
@NonNull
public Boolean partial_fetch = true; public Boolean partial_fetch = true;
@NonNull @NonNull
public Boolean ignore_size = false; public Boolean ignore_size = false;

@ -1112,6 +1112,7 @@ public class FragmentAccount extends FragmentBase {
if (account.poll_interval != poll_interval) { if (account.poll_interval != poll_interval) {
account.keep_alive_ok = false; account.keep_alive_ok = false;
account.keep_alive_failed = 0; account.keep_alive_failed = 0;
account.keep_alive_succeeded = 0;
} }
account.poll_interval = poll_interval; account.poll_interval = poll_interval;

@ -1358,28 +1358,40 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
} catch (Throwable ex) { } catch (Throwable ex) {
if (optimize) { if (optimize) {
account.keep_alive_failed++; account.keep_alive_failed++;
account.keep_alive_succeeded = 0;
if (account.keep_alive_failed >= 3) { if (account.keep_alive_failed >= 3) {
account.keep_alive_failed = 0; account.keep_alive_failed = 0;
account.poll_interval--; account.poll_interval--;
db.account().setAccountKeepAliveInterval(account.id, account.poll_interval); db.account().setAccountKeepAliveInterval(account.id, account.poll_interval);
} }
db.account().setAccountKeepAliveFailed(account.id, account.keep_alive_failed); db.account().setAccountKeepAliveValues(account.id,
EntityLog.log(ServiceSynchronize.this, account.name + account.keep_alive_failed, account.keep_alive_succeeded);
" keep alive failed=" + account.keep_alive_failed + EntityLog.log(ServiceSynchronize.this, account.name + " keep alive" +
" keep alive interval=" + account.poll_interval + " failed=" + account.keep_alive_failed +
" max idle=" + idleTime + "/" + optimize); " succeeded=" + account.keep_alive_succeeded +
" interval=" + account.poll_interval +
" idle=" + idleTime);
} }
throw ex; throw ex;
} }
if (optimize) { if (optimize) {
account.keep_alive_ok = true;
account.keep_alive_failed = 0; account.keep_alive_failed = 0;
account.keep_alive_succeeded++;
db.account().setAccountKeepAliveValues(account.id,
account.keep_alive_failed, account.keep_alive_succeeded);
if (account.keep_alive_succeeded >= 3) {
account.keep_alive_ok = true;
db.account().setAccountKeepAliveOk(account.id, true); db.account().setAccountKeepAliveOk(account.id, true);
db.account().setAccountKeepAliveFailed(account.id, account.keep_alive_failed);
if (!BuildConfig.PLAY_STORE_RELEASE) if (!BuildConfig.PLAY_STORE_RELEASE)
Log.e(account.host + " keep alive=" + account.poll_interval); Log.e(account.host + " keep alive=" + account.poll_interval);
EntityLog.log(ServiceSynchronize.this, account.name + " keep alive ok"); EntityLog.log(ServiceSynchronize.this, account.name + " keep alive ok");
} else
EntityLog.log(ServiceSynchronize.this, account.name + " keep alive" +
" failed=" + account.keep_alive_failed +
" succeeded=" + account.keep_alive_succeeded +
" interval=" + account.poll_interval +
" idle=" + idleTime);
} }
// Successfully connected: reset back off time // Successfully connected: reset back off time

Loading…
Cancel
Save