Enable DB optimize

pull/207/head
M66B 3 years ago
parent 06f1ae4c72
commit fba2ab9870

@ -140,6 +140,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private ImageButton ibRoom;
private SwitchCompat swWal;
private SwitchCompat swCheckpoints;
private SwitchCompat swAnalyze;
private TextView tvSqliteCache;
private SeekBar sbSqliteCache;
private TextView tvChunkSize;
@ -196,7 +197,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
"experiments", "crash_reports", "cleanup_attachments",
"protocol", "debug", "log_level", "test1", "test2", "test3", "test4", "test5",
"work_manager", // "external_storage",
"query_threads", "wal", "checkpoints", "sqlite_cache",
"query_threads", "wal", "checkpoints", "sqlite_analyze", "sqlite_cache",
"chunk_size", "undo_manager", "webview_legacy",
"use_modseq", "uid_command", "perform_expunge", "uid_expunge",
"auth_plain", "auth_login", "auth_ntlm", "auth_sasl", "auth_apop",
@ -294,6 +295,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
ibRoom = view.findViewById(R.id.ibRoom);
swWal = view.findViewById(R.id.swWal);
swCheckpoints = view.findViewById(R.id.swCheckpoints);
swAnalyze = view.findViewById(R.id.swAnalyze);
tvSqliteCache = view.findViewById(R.id.tvSqliteCache);
sbSqliteCache = view.findViewById(R.id.sbSqliteCache);
ibSqliteCache = view.findViewById(R.id.ibSqliteCache);
@ -883,6 +885,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
swAnalyze.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("sqlite_analyze", checked).apply();
}
});
sbSqliteCache.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
@ -1594,6 +1603,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swWal.setChecked(prefs.getBoolean("wal", true));
swCheckpoints.setChecked(prefs.getBoolean("checkpoints", true));
swAnalyze.setChecked(prefs.getBoolean("sqlite_analyze", true));
int sqlite_cache = prefs.getInt("sqlite_cache", DB.DEFAULT_CACHE_SIZE);
Integer cache_size = DB.getCacheSizeKb(getContext());

@ -97,6 +97,7 @@ public class WorkerCleanup extends Worker {
boolean cleanup_attachments = prefs.getBoolean("cleanup_attachments", false);
boolean download_headers = prefs.getBoolean("download_headers", false);
boolean download_eml = prefs.getBoolean("download_eml", false);
boolean sqlite_analyze = prefs.getBoolean("sqlite_analyze", true);
long start = new Date().getTime();
DB db = DB.getInstance(context);
@ -339,9 +340,9 @@ public class WorkerCleanup extends Worker {
db.endTransaction();
}
if (BuildConfig.DEBUG) {
if (sqlite_analyze) {
// https://sqlite.org/lang_analyze.html
Log.i("Analyze");
Log.i("Running analyze");
long analyze = new Date().getTime();
try (Cursor cursor = db.getOpenHelper().getWritableDatabase().query("PRAGMA analysis_limit=1000; PRAGMA optimize;")) {
cursor.moveToNext();

@ -779,6 +779,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_wal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@ -790,12 +791,25 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_checkpoints"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swWal"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAnalyze"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_analyze"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swCheckpoints"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvSqliteCache"
android:layout_width="0dp"
@ -806,7 +820,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swCheckpoints" />
app:layout_constraintTop_toBottomOf="@id/swAnalyze" />
<SeekBar
android:id="@+id/sbSqliteCache"

@ -708,6 +708,7 @@
<string name="title_advanced_room_query_threads" translatable="false">ROOM query threads: %1$s</string>
<string name="title_advanced_wal" translatable="false">WAL</string>
<string name="title_advanced_checkpoints" translatable="false">Checkpoints</string>
<string name="title_advanced_analyze" translatable="false">Analyze</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_undo_manager" translatable="false">Use Android\'s undo manager</string>

Loading…
Cancel
Save