Added option to limit query threads

pull/182/head
M66B 4 years ago
parent 6513454f68
commit 8d5971f587

@ -106,8 +106,6 @@ public abstract class DB extends RoomDatabase {
public abstract DaoLog log(); public abstract DaoLog log();
private static DB sInstance; private static DB sInstance;
private static final ExecutorService executor =
Helper.getBackgroundExecutor(2, "query"); // AndroidX default thread count: 4
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
@ -261,6 +259,11 @@ public abstract class DB extends RoomDatabase {
Log.e(ex); Log.e(ex);
} }
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int threads = prefs.getInt("query_threads", 4); // AndroidX default thread count: 4
Log.i("Query threads=" + threads);
ExecutorService executor = Helper.getBackgroundExecutor(threads, "query");
return Room return Room
.databaseBuilder(context, DB.class, DB_NAME) .databaseBuilder(context, DB.class, DB_NAME)
.openHelperFactory(new RequerySQLiteOpenHelperFactory()) .openHelperFactory(new RequerySQLiteOpenHelperFactory())

@ -76,6 +76,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swUpdates; private SwitchCompat swUpdates;
private SwitchCompat swExperiments; private SwitchCompat swExperiments;
private TextView tvExperimentsHint; private TextView tvExperimentsHint;
private SwitchCompat swQueries;
private SwitchCompat swCrashReports; private SwitchCompat swCrashReports;
private TextView tvUuid; private TextView tvUuid;
private SwitchCompat swDebug; private SwitchCompat swDebug;
@ -98,7 +99,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private final static String[] RESET_OPTIONS = new String[]{ private final static String[] RESET_OPTIONS = new String[]{
"shortcuts", "fts", "english", "watchdog", "updates", "shortcuts", "fts", "english", "watchdog", "updates",
"experiments", "crash_reports", "debug", "auth_sasl", "cleanup_attachments" "experiments", "query_threads", "crash_reports", "debug", "auth_sasl", "cleanup_attachments"
}; };
private final static String[] RESET_QUESTIONS = new String[]{ private final static String[] RESET_QUESTIONS = new String[]{
@ -131,6 +132,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swUpdates = view.findViewById(R.id.swUpdates); swUpdates = view.findViewById(R.id.swUpdates);
swExperiments = view.findViewById(R.id.swExperiments); swExperiments = view.findViewById(R.id.swExperiments);
tvExperimentsHint = view.findViewById(R.id.tvExperimentsHint); tvExperimentsHint = view.findViewById(R.id.tvExperimentsHint);
swQueries = view.findViewById(R.id.swQueries);
swCrashReports = view.findViewById(R.id.swCrashReports); swCrashReports = view.findViewById(R.id.swCrashReports);
tvUuid = view.findViewById(R.id.tvUuid); tvUuid = view.findViewById(R.id.tvUuid);
swDebug = view.findViewById(R.id.swDebug); swDebug = view.findViewById(R.id.swDebug);
@ -259,6 +261,14 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
} }
}); });
swQueries.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putInt("query_threads", checked ? 2 : 4).commit(); // apply won't work here
restart();
}
});
swCrashReports.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swCrashReports.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -536,6 +546,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
Helper.isPlayStoreInstall() || !Helper.hasValidFingerprint(getContext()) Helper.isPlayStoreInstall() || !Helper.hasValidFingerprint(getContext())
? View.GONE : View.VISIBLE); ? View.GONE : View.VISIBLE);
swExperiments.setChecked(prefs.getBoolean("experiments", false)); swExperiments.setChecked(prefs.getBoolean("experiments", false));
swQueries.setChecked(prefs.getInt("query_threads", 4) < 4);
swCrashReports.setChecked(prefs.getBoolean("crash_reports", false)); swCrashReports.setChecked(prefs.getBoolean("crash_reports", false));
tvUuid.setText(prefs.getString("uuid", null)); tvUuid.setText(prefs.getString("uuid", null));
swDebug.setChecked(prefs.getBoolean("debug", false)); swDebug.setChecked(prefs.getBoolean("debug", false));

@ -183,6 +183,29 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swExperiments" /> app:layout_constraintTop_toBottomOf="@id/swExperiments" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swQueries"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_query_threads"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvExperimentsHint"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvQueriesHint"
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/swQueries" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swCrashReports" android:id="@+id/swCrashReports"
android:layout_width="0dp" android:layout_width="0dp"
@ -191,7 +214,7 @@
android:text="@string/title_advanced_crash_reports" android:text="@string/title_advanced_crash_reports"
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/tvExperimentsHint" app:layout_constraintTop_toBottomOf="@id/tvQueriesHint"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView

@ -466,6 +466,7 @@
<string name="title_advanced_optimize">Automatically optimize</string> <string name="title_advanced_optimize">Automatically optimize</string>
<string name="title_advanced_updates">Check for updates</string> <string name="title_advanced_updates">Check for updates</string>
<string name="title_advanced_experiments">Try experimental features</string> <string name="title_advanced_experiments">Try experimental features</string>
<string name="title_advanced_query_threads">Limit parallel database reads</string>
<string name="title_advanced_crash_reports">Send error reports</string> <string name="title_advanced_crash_reports">Send error reports</string>
<string name="title_advanced_debug">Debug mode</string> <string name="title_advanced_debug">Debug mode</string>
<string name="title_advanced_cleanup_attachments">Delete attachments of old messages</string> <string name="title_advanced_cleanup_attachments">Delete attachments of old messages</string>

Loading…
Cancel
Save