Sqlite sync extra

This commit is contained in:
M66B 2022-08-31 09:09:42 +02:00
parent b4167551df
commit 75b688dad0
5 changed files with 55 additions and 6 deletions

View File

@ -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");

View File

@ -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) {

View File

@ -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());

View File

@ -1085,6 +1085,30 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAutoVacuum" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSyncExtra"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_sync_extra"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAutoVacuumHint"
app:switchPadding="12dp" />
<TextView
android:id="@+id/tvSyncExtraHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_english_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSyncExtra" />
<TextView
android:id="@+id/tvSqliteCache"
android:layout_width="0dp"
@ -1095,7 +1119,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAutoVacuumHint" />
app:layout_constraintTop_toBottomOf="@id/tvSyncExtraHint" />
<SeekBar
android:id="@+id/sbSqliteCache"

View File

@ -782,6 +782,7 @@
<string name="title_advanced_checkpoints" translatable="false">sqlite checkpoints</string>
<string name="title_advanced_analyze" translatable="false">sqlite analyze</string>
<string name="title_advanced_auto_vacuum" translatable="false">sqlite auto vacuum</string>
<string name="title_advanced_sync_extra" translatable="false">sqlite sync extra</string>
<string name="title_advanced_sqlite_cache" translatable="false">sqlite cache: %1$s %% - %2$s</string>
<string name="title_advanced_chunk_size" translatable="false">Chunk size: %1$d</string>
<string name="title_advanced_thread_range" translatable="false">Thread range: %1$d days</string>