mirror of https://github.com/M66B/FairEmail.git
Added debug option to configure sqlite cache size
This commit is contained in:
parent
c4c9499211
commit
aaf4187631
|
@ -245,7 +245,7 @@ public class ApplicationEx extends Application
|
||||||
case "query_threads": // misc
|
case "query_threads": // misc
|
||||||
case "wal": // misc
|
case "wal": // misc
|
||||||
// Should be excluded for import
|
// Should be excluded for import
|
||||||
restart();
|
restart(this);
|
||||||
break;
|
break;
|
||||||
case "debug":
|
case "debug":
|
||||||
case "log_level":
|
case "log_level":
|
||||||
|
@ -254,10 +254,10 @@ public class ApplicationEx extends Application
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void restart() {
|
static void restart(Context context) {
|
||||||
Intent intent = new Intent(this, ActivityMain.class);
|
Intent intent = new Intent(context, ActivityMain.class);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
startActivity(intent);
|
context.startActivity(intent);
|
||||||
Runtime.getRuntime().exit(0);
|
Runtime.getRuntime().exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -117,9 +117,10 @@ public abstract class DB extends RoomDatabase {
|
||||||
private static Context sContext;
|
private static Context sContext;
|
||||||
private static DB sInstance;
|
private static DB sInstance;
|
||||||
|
|
||||||
|
static final int DB_DEFAULT_CACHE = 5; // percentage
|
||||||
|
|
||||||
private static final String DB_NAME = "fairemail";
|
private static final String DB_NAME = "fairemail";
|
||||||
private static final int DB_CHECKPOINT = 1000; // requery/sqlite-android default
|
private static final int DB_CHECKPOINT = 1000; // requery/sqlite-android default
|
||||||
private static final int DB_CACHE_PERCENTAGE = 3;
|
|
||||||
|
|
||||||
private static final String[] DB_TABLES = new String[]{
|
private static final String[] DB_TABLES = new String[]{
|
||||||
"identity", "account", "folder", "message", "attachment", "operation", "contact", "certificate", "answer", "rule", "log"};
|
"identity", "account", "folder", "message", "attachment", "operation", "contact", "certificate", "answer", "rule", "log"};
|
||||||
|
@ -374,6 +375,7 @@ public abstract class DB extends RoomDatabase {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
int threads = prefs.getInt("query_threads", 4); // AndroidX default thread count: 4
|
int threads = prefs.getInt("query_threads", 4); // AndroidX default thread count: 4
|
||||||
boolean wal = prefs.getBoolean("wal", true);
|
boolean wal = prefs.getBoolean("wal", true);
|
||||||
|
int sqlite_cache = prefs.getInt("sqlite_cache", DB.DB_DEFAULT_CACHE);
|
||||||
Log.i("DB query threads=" + threads + " wal=" + wal);
|
Log.i("DB query threads=" + threads + " wal=" + wal);
|
||||||
ExecutorService executorQuery = Helper.getBackgroundExecutor(threads, "query");
|
ExecutorService executorQuery = Helper.getBackgroundExecutor(threads, "query");
|
||||||
ExecutorService executorTransaction = Helper.getBackgroundExecutor(0, "transaction");
|
ExecutorService executorTransaction = Helper.getBackgroundExecutor(0, "transaction");
|
||||||
|
@ -404,7 +406,7 @@ public abstract class DB extends RoomDatabase {
|
||||||
try {
|
try {
|
||||||
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
int class_mb = am.getMemoryClass();
|
int class_mb = am.getMemoryClass();
|
||||||
int cache_size = DB_CACHE_PERCENTAGE * class_mb * 1024 / 100;
|
int cache_size = sqlite_cache * class_mb * 1024 / 100;
|
||||||
if (cache_size > 2000) {
|
if (cache_size > 2000) {
|
||||||
// https://www.sqlite.org/pragma.html#pragma_cache_size
|
// https://www.sqlite.org/pragma.html#pragma_cache_size
|
||||||
cache_size = -cache_size; // kibibytes
|
cache_size = -cache_size; // kibibytes
|
||||||
|
|
|
@ -124,6 +124,9 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||||
private SwitchCompat swDebug;
|
private SwitchCompat swDebug;
|
||||||
private SwitchCompat swQueries;
|
private SwitchCompat swQueries;
|
||||||
private SwitchCompat swWal;
|
private SwitchCompat swWal;
|
||||||
|
private TextView tvSqliteCache;
|
||||||
|
private SeekBar sbSqliteCache;
|
||||||
|
private ImageButton ibSqliteCache;
|
||||||
private SwitchCompat swModSeq;
|
private SwitchCompat swModSeq;
|
||||||
private SwitchCompat swExpunge;
|
private SwitchCompat swExpunge;
|
||||||
private SwitchCompat swAuthPlain;
|
private SwitchCompat swAuthPlain;
|
||||||
|
@ -154,7 +157,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||||
"shortcuts", "fts",
|
"shortcuts", "fts",
|
||||||
"classification", "class_min_probability", "class_min_difference",
|
"classification", "class_min_probability", "class_min_difference",
|
||||||
"language", "deepl_enabled", "watchdog", "updates", "weekly",
|
"language", "deepl_enabled", "watchdog", "updates", "weekly",
|
||||||
"experiments", "wal", "query_threads", "crash_reports", "cleanup_attachments",
|
"experiments", "wal", "query_threads", "sqlite_cache", "crash_reports", "cleanup_attachments",
|
||||||
"protocol", "debug", "log_level",
|
"protocol", "debug", "log_level",
|
||||||
"use_modseq", "perform_expunge",
|
"use_modseq", "perform_expunge",
|
||||||
"auth_plain", "auth_login", "auth_ntlm", "auth_sasl",
|
"auth_plain", "auth_login", "auth_ntlm", "auth_sasl",
|
||||||
|
@ -236,6 +239,9 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||||
swDebug = view.findViewById(R.id.swDebug);
|
swDebug = view.findViewById(R.id.swDebug);
|
||||||
swQueries = view.findViewById(R.id.swQueries);
|
swQueries = view.findViewById(R.id.swQueries);
|
||||||
swWal = view.findViewById(R.id.swWal);
|
swWal = view.findViewById(R.id.swWal);
|
||||||
|
tvSqliteCache = view.findViewById(R.id.tvSqliteCache);
|
||||||
|
sbSqliteCache = view.findViewById(R.id.sbSqliteCache);
|
||||||
|
ibSqliteCache = view.findViewById(R.id.ibSqliteCache);
|
||||||
swModSeq = view.findViewById(R.id.swModSeq);
|
swModSeq = view.findViewById(R.id.swModSeq);
|
||||||
swExpunge = view.findViewById(R.id.swExpunge);
|
swExpunge = view.findViewById(R.id.swExpunge);
|
||||||
swAuthPlain = view.findViewById(R.id.swAuthPlain);
|
swAuthPlain = view.findViewById(R.id.swAuthPlain);
|
||||||
|
@ -608,6 +614,30 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
sbSqliteCache.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
|
prefs.edit().putInt("sqlite_cache", progress).apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ibSqliteCache.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
ApplicationEx.restart(v.getContext());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
swProtocol.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
swProtocol.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||||
|
@ -1010,6 +1040,12 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||||
private void setOptions() {
|
private void setOptions() {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
|
|
||||||
|
ActivityManager am = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
int class_mb = am.getMemoryClass();
|
||||||
|
int class_large_mb = am.getLargeMemoryClass();
|
||||||
|
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
|
||||||
|
am.getMemoryInfo(mi);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
||||||
swPowerMenu.setChecked(Helper.isComponentEnabled(getContext(), ServicePowerControl.class));
|
swPowerMenu.setChecked(Helper.isComponentEnabled(getContext(), ServicePowerControl.class));
|
||||||
swExternalSearch.setChecked(Helper.isComponentEnabled(getContext(), ActivitySearch.class));
|
swExternalSearch.setChecked(Helper.isComponentEnabled(getContext(), ActivitySearch.class));
|
||||||
|
@ -1061,6 +1097,14 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||||
swDebug.setChecked(prefs.getBoolean("debug", false));
|
swDebug.setChecked(prefs.getBoolean("debug", false));
|
||||||
swQueries.setChecked(prefs.getInt("query_threads", 4) < 4);
|
swQueries.setChecked(prefs.getInt("query_threads", 4) < 4);
|
||||||
swWal.setChecked(prefs.getBoolean("wal", true));
|
swWal.setChecked(prefs.getBoolean("wal", true));
|
||||||
|
|
||||||
|
int sqlite_cache = prefs.getInt("sqlite_cache", DB.DB_DEFAULT_CACHE);
|
||||||
|
int cache_size = sqlite_cache * class_mb * 1024 / 100;
|
||||||
|
tvSqliteCache.setText(getString(R.string.title_advanced_sqlite_cache,
|
||||||
|
NF.format(sqlite_cache),
|
||||||
|
Helper.humanReadableByteCount(cache_size * 1024L)));
|
||||||
|
sbSqliteCache.setProgress(sqlite_cache);
|
||||||
|
|
||||||
swModSeq.setChecked(prefs.getBoolean("use_modseq", true));
|
swModSeq.setChecked(prefs.getBoolean("use_modseq", true));
|
||||||
swExpunge.setChecked(prefs.getBoolean("perform_expunge", true));
|
swExpunge.setChecked(prefs.getBoolean("perform_expunge", true));
|
||||||
swAuthPlain.setChecked(prefs.getBoolean("auth_plain", true));
|
swAuthPlain.setChecked(prefs.getBoolean("auth_plain", true));
|
||||||
|
@ -1071,12 +1115,6 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||||
swTestIab.setChecked(prefs.getBoolean("test_iab", false));
|
swTestIab.setChecked(prefs.getBoolean("test_iab", false));
|
||||||
|
|
||||||
tvProcessors.setText(getString(R.string.title_advanced_processors, Runtime.getRuntime().availableProcessors()));
|
tvProcessors.setText(getString(R.string.title_advanced_processors, Runtime.getRuntime().availableProcessors()));
|
||||||
|
|
||||||
ActivityManager am = (ActivityManager) getContext().getSystemService(Context.ACTIVITY_SERVICE);
|
|
||||||
int class_mb = am.getMemoryClass();
|
|
||||||
int class_large_mb = am.getLargeMemoryClass();
|
|
||||||
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
|
|
||||||
am.getMemoryInfo(mi);
|
|
||||||
tvMemoryClass.setText(getString(R.string.title_advanced_memory_class,
|
tvMemoryClass.setText(getString(R.string.title_advanced_memory_class,
|
||||||
class_mb + " MB",
|
class_mb + " MB",
|
||||||
class_large_mb + " MB",
|
class_large_mb + " MB",
|
||||||
|
|
|
@ -640,6 +640,50 @@
|
||||||
app:layout_constraintTop_toBottomOf="@id/tvQueriesRemark"
|
app:layout_constraintTop_toBottomOf="@id/tvQueriesRemark"
|
||||||
app:switchPadding="12dp" />
|
app:switchPadding="12dp" />
|
||||||
|
|
||||||
|
<eu.faircode.email.FixedTextView
|
||||||
|
android:id="@+id/tvSqliteCache"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:layout_marginEnd="48dp"
|
||||||
|
android:text="@string/title_advanced_sqlite_cache"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/swWal" />
|
||||||
|
|
||||||
|
<SeekBar
|
||||||
|
android:id="@+id/sbSqliteCache"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:max="20"
|
||||||
|
android:min="0"
|
||||||
|
android:progress="5"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvSqliteCache" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/ibSqliteCache"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/sbSqliteCache"
|
||||||
|
app:srcCompat="@drawable/twotone_check_24" />
|
||||||
|
|
||||||
|
<eu.faircode.email.FixedTextView
|
||||||
|
android:id="@+id/tvSqliteCacheHint"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
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/ibSqliteCache" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
android:id="@+id/swModSeq"
|
android:id="@+id/swModSeq"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
@ -649,7 +693,7 @@
|
||||||
android:text="@string/title_advanced_modseq"
|
android:text="@string/title_advanced_modseq"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@id/swWal"
|
app:layout_constraintTop_toBottomOf="@id/tvSqliteCacheHint"
|
||||||
app:switchPadding="12dp" />
|
app:switchPadding="12dp" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.SwitchCompat
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
|
|
|
@ -623,6 +623,7 @@
|
||||||
<string name="title_advanced_debug">Debug mode</string>
|
<string name="title_advanced_debug">Debug mode</string>
|
||||||
<string name="title_advanced_query_threads">Limit parallel database access</string>
|
<string name="title_advanced_query_threads">Limit parallel database access</string>
|
||||||
<string name="title_advanced_wal" translatable="false">WAL</string>
|
<string name="title_advanced_wal" translatable="false">WAL</string>
|
||||||
|
<string name="title_advanced_sqlite_cache" translatable="false">Sqlite cache %1$s %% - %2$s</string>
|
||||||
<string name="title_advanced_modseq" translatable="false">MODSEQ</string>
|
<string name="title_advanced_modseq" translatable="false">MODSEQ</string>
|
||||||
<string name="title_advanced_expunge" translatable="false">EXPUNGE</string>
|
<string name="title_advanced_expunge" translatable="false">EXPUNGE</string>
|
||||||
<string name="title_advanced_auth_plain" translatable="false">PLAIN</string>
|
<string name="title_advanced_auth_plain" translatable="false">PLAIN</string>
|
||||||
|
|
Loading…
Reference in New Issue