From 75b688dad028ce80211920ef784a33cdfe6b7eed Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 31 Aug 2022 09:09:42 +0200 Subject: [PATCH] Sqlite sync extra --- .../java/eu/faircode/email/ApplicationEx.java | 3 ++- app/src/main/java/eu/faircode/email/DB.java | 10 ++++++- .../faircode/email/FragmentOptionsMisc.java | 21 ++++++++++++--- .../main/res/layout/fragment_options_misc.xml | 26 ++++++++++++++++++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 55 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ApplicationEx.java b/app/src/main/java/eu/faircode/email/ApplicationEx.java index 6ebb4a73c5..c79755479e 100644 --- a/app/src/main/java/eu/faircode/email/ApplicationEx.java +++ b/app/src/main/java/eu/faircode/email/ApplicationEx.java @@ -651,7 +651,8 @@ public class ApplicationEx extends Application } else if (version < 1955) { if (!prefs.contains("doubletap")) editor.putBoolean("doubletap", true); - } + } else if (version < 1960) + editor.remove("sqlite_auto_vacuum"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !BuildConfig.DEBUG) editor.remove("background_service"); diff --git a/app/src/main/java/eu/faircode/email/DB.java b/app/src/main/java/eu/faircode/email/DB.java index ccb11e74b1..af9a94bc7b 100644 --- a/app/src/main/java/eu/faircode/email/DB.java +++ b/app/src/main/java/eu/faircode/email/DB.java @@ -410,13 +410,21 @@ public abstract class DB extends RoomDatabase { // https://www.sqlite.org/pragma.html#pragma_auto_vacuum // https://android.googlesource.com/platform/external/sqlite.git/+/6ab557bdc070f11db30ede0696888efd19800475%5E!/ - boolean sqlite_auto_vacuum = prefs.getBoolean("sqlite_auto_vacuum", !Helper.isRedmiNote()); + boolean sqlite_auto_vacuum = prefs.getBoolean("sqlite_auto_vacuum", false); String mode = (sqlite_auto_vacuum ? "FULL" : "INCREMENTAL"); Log.i("Set PRAGMA auto_vacuum = " + mode); try (Cursor cursor = db.query("PRAGMA auto_vacuum = " + mode + ";", null)) { cursor.moveToNext(); // required } + // https://sqlite.org/pragma.html#pragma_synchronous + boolean sqlite_sync_extra = prefs.getBoolean("sqlite_sync_extra", true); + String sync = (sqlite_sync_extra ? "EXTRA" : "NORMAL"); + Log.i("Set PRAGMA synchronous = " + sync); + try (Cursor cursor = db.query("PRAGMA synchronous = " + sync + ";", null)) { + cursor.moveToNext(); // required + } + // https://www.sqlite.org/pragma.html#pragma_cache_size Integer cache_size = getCacheSizeKb(context); if (cache_size != null) { diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java index ecfabbbb2b..758b82af66 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java @@ -168,6 +168,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc private SwitchCompat swCheckpoints; private SwitchCompat swAnalyze; private SwitchCompat swAutoVacuum; + private SwitchCompat swSyncExtra; private TextView tvSqliteCache; private SeekBar sbSqliteCache; private TextView tvChunkSize; @@ -237,7 +238,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc "watchdog", "experiments", "main_log", "protocol", "log_level", "debug", "leak_canary", "test1", "test2", "test3", "test4", "test5", "work_manager", // "external_storage", - "query_threads", "wal", "sqlite_checkpoints", "sqlite_analyze", "sqlite_auto_vacuum", "sqlite_cache", + "query_threads", "wal", + "sqlite_checkpoints", "sqlite_analyze", "sqlite_auto_vacuum", "sqlite_sync_extra", "sqlite_cache", "chunk_size", "thread_range", "undo_manager", "webview_legacy", "browser_zoom", "fake_dark", "show_recent", @@ -365,6 +367,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swCheckpoints = view.findViewById(R.id.swCheckpoints); swAnalyze = view.findViewById(R.id.swAnalyze); swAutoVacuum = view.findViewById(R.id.swAutoVacuum); + swSyncExtra = view.findViewById(R.id.swSyncExtra); tvSqliteCache = view.findViewById(R.id.tvSqliteCache); sbSqliteCache = view.findViewById(R.id.sbSqliteCache); ibSqliteCache = view.findViewById(R.id.ibSqliteCache); @@ -1121,11 +1124,22 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc prefs.edit() .putBoolean("sqlite_auto_vacuum", checked) .remove("debug") - .apply(); + .commit(); ApplicationEx.restart(v.getContext(), "sqlite_auto_vacuum"); } }); + swSyncExtra.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton v, boolean checked) { + prefs.edit() + .putBoolean("sqlite_sync_extra", checked) + .remove("debug") + .commit(); + ApplicationEx.restart(v.getContext(), "sqlite_sync_extra"); + } + }); + sbSqliteCache.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { @@ -1964,7 +1978,8 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc swWal.setChecked(prefs.getBoolean("wal", true)); swCheckpoints.setChecked(prefs.getBoolean("sqlite_checkpoints", true)); swAnalyze.setChecked(prefs.getBoolean("sqlite_analyze", true)); - swAutoVacuum.setChecked(prefs.getBoolean("sqlite_auto_vacuum", !Helper.isRedmiNote())); + swAutoVacuum.setChecked(prefs.getBoolean("sqlite_auto_vacuum", false)); + swSyncExtra.setChecked(prefs.getBoolean("sqlite_sync_extra", true)); int sqlite_cache = prefs.getInt("sqlite_cache", DB.DEFAULT_CACHE_SIZE); Integer cache_size = DB.getCacheSizeKb(getContext()); diff --git a/app/src/main/res/layout/fragment_options_misc.xml b/app/src/main/res/layout/fragment_options_misc.xml index c08b574fca..53cd692ac2 100644 --- a/app/src/main/res/layout/fragment_options_misc.xml +++ b/app/src/main/res/layout/fragment_options_misc.xml @@ -1085,6 +1085,30 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/swAutoVacuum" /> + + + + + app:layout_constraintTop_toBottomOf="@id/tvSyncExtraHint" /> sqlite checkpoints sqlite analyze sqlite auto vacuum + sqlite sync extra sqlite cache: %1$s %% - %2$s Chunk size: %1$d Thread range: %1$d days