Added setting for number of query threads

pull/205/head
M66B 4 years ago
parent 946b7d1c7b
commit 78e801bc95

@ -117,7 +117,8 @@ 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 static final int DEFAULT_QUERY_THREADS = 4; // AndroidX default thread count: 4
static final int DEFAULT_CACHE_SIZE = 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
@ -373,9 +374,9 @@ 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", DEFAULT_QUERY_THREADS);
boolean wal = prefs.getBoolean("wal", true); boolean wal = prefs.getBoolean("wal", true);
int sqlite_cache = prefs.getInt("sqlite_cache", DB.DB_DEFAULT_CACHE); int sqlite_cache = prefs.getInt("sqlite_cache", DEFAULT_CACHE_SIZE);
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");

@ -118,11 +118,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private TextView tvLastCleanup; private TextView tvLastCleanup;
private Button btnApp; private Button btnApp;
private Button btnMore; private Button btnMore;
private SwitchCompat swProtocol; private SwitchCompat swProtocol;
private SwitchCompat swLogInfo; private SwitchCompat swLogInfo;
private SwitchCompat swDebug; private SwitchCompat swDebug;
private SwitchCompat swQueries;
private TextView tvRoomQueryThreads;
private SeekBar sbRoomQueryThreads;
private ImageButton ibRoom;
private SwitchCompat swWal; private SwitchCompat swWal;
private SwitchCompat swCheckpoints; private SwitchCompat swCheckpoints;
private TextView tvSqliteCache; private TextView tvSqliteCache;
@ -234,11 +236,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
tvLastCleanup = view.findViewById(R.id.tvLastCleanup); tvLastCleanup = view.findViewById(R.id.tvLastCleanup);
btnApp = view.findViewById(R.id.btnApp); btnApp = view.findViewById(R.id.btnApp);
btnMore = view.findViewById(R.id.btnMore); btnMore = view.findViewById(R.id.btnMore);
swProtocol = view.findViewById(R.id.swProtocol); swProtocol = view.findViewById(R.id.swProtocol);
swLogInfo = view.findViewById(R.id.swLogInfo); swLogInfo = view.findViewById(R.id.swLogInfo);
swDebug = view.findViewById(R.id.swDebug); swDebug = view.findViewById(R.id.swDebug);
swQueries = view.findViewById(R.id.swQueries);
tvRoomQueryThreads = view.findViewById(R.id.tvRoomQueryThreads);
sbRoomQueryThreads = view.findViewById(R.id.sbRoomQueryThreads);
ibRoom = view.findViewById(R.id.ibRoom);
swWal = view.findViewById(R.id.swWal); swWal = view.findViewById(R.id.swWal);
swCheckpoints = view.findViewById(R.id.swCheckpoints); swCheckpoints = view.findViewById(R.id.swCheckpoints);
tvSqliteCache = view.findViewById(R.id.tvSqliteCache); tvSqliteCache = view.findViewById(R.id.tvSqliteCache);
@ -599,13 +603,27 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
} }
}); });
swQueries.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { sbRoomQueryThreads.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (checked) prefs.edit().putInt("query_threads", progress).apply();
prefs.edit().putInt("query_threads", 2).commit(); // apply won't work here }
else
prefs.edit().remove("query_threads").commit(); // apply won't work here @Override
public void onStartTrackingTouch(SeekBar seekBar) {
// Do nothing
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// Do nothing
}
});
ibRoom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ApplicationEx.restart(v.getContext());
} }
}); });
@ -1104,11 +1122,15 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swProtocol.setChecked(prefs.getBoolean("protocol", false)); swProtocol.setChecked(prefs.getBoolean("protocol", false));
swLogInfo.setChecked(prefs.getInt("log_level", Log.getDefaultLogLevel()) <= android.util.Log.INFO); swLogInfo.setChecked(prefs.getInt("log_level", Log.getDefaultLogLevel()) <= android.util.Log.INFO);
swDebug.setChecked(prefs.getBoolean("debug", false)); swDebug.setChecked(prefs.getBoolean("debug", false));
swQueries.setChecked(prefs.getInt("query_threads", 4) < 4);
int query_threads = prefs.getInt("query_threads", DB.DEFAULT_QUERY_THREADS);
tvRoomQueryThreads.setText(getString(R.string.title_advanced_room_query_threads, NF.format(query_threads)));
sbRoomQueryThreads.setProgress(query_threads);
swWal.setChecked(prefs.getBoolean("wal", true)); swWal.setChecked(prefs.getBoolean("wal", true));
swCheckpoints.setChecked(prefs.getBoolean("checkpoints", true)); swCheckpoints.setChecked(prefs.getBoolean("checkpoints", true));
int sqlite_cache = prefs.getInt("sqlite_cache", DB.DB_DEFAULT_CACHE); int sqlite_cache = prefs.getInt("sqlite_cache", DB.DEFAULT_CACHE_SIZE);
int cache_size = sqlite_cache * class_mb * 1024 / 100; int cache_size = sqlite_cache * class_mb * 1024 / 100;
tvSqliteCache.setText(getString(R.string.title_advanced_sqlite_cache, tvSqliteCache.setText(getString(R.string.title_advanced_sqlite_cache,
NF.format(sqlite_cache), NF.format(sqlite_cache),

@ -594,31 +594,40 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.SwitchCompat <eu.faircode.email.FixedTextView
android:id="@+id/swQueries" android:id="@+id/tvRoomQueryThreads"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_advanced_query_threads" android:layout_marginEnd="48dp"
android:text="@string/title_advanced_room_query_threads"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
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/tvCaptionDebug" app:layout_constraintTop_toBottomOf="@id/tvCaptionDebug" />
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView <SeekBar
android:id="@+id/tvQueriesHint" android:id="@+id/sbRoomQueryThreads"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="48dp" android:max="32"
android:text="@string/title_advanced_queries_hint" android:min="0"
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:progress="4"
android:textStyle="italic"
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/swQueries" /> app:layout_constraintTop_toBottomOf="@id/tvRoomQueryThreads" />
<ImageButton
android:id="@+id/ibRoom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/sbRoomQueryThreads"
app:srcCompat="@drawable/twotone_check_24" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView
android:id="@+id/tvQueriesRemark" android:id="@+id/tvRoomHint"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="48dp" android:layout_marginEnd="48dp"
@ -627,7 +636,7 @@
android:textStyle="italic" android:textStyle="italic"
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/tvQueriesHint" /> app:layout_constraintTop_toBottomOf="@id/ibRoom" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swWal" android:id="@+id/swWal"
@ -637,7 +646,7 @@
android:text="@string/title_advanced_wal" android:text="@string/title_advanced_wal"
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/tvQueriesRemark" app:layout_constraintTop_toBottomOf="@id/tvRoomHint"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat

@ -628,7 +628,7 @@
<string name="title_advanced_protocol">Protocol logging</string> <string name="title_advanced_protocol">Protocol logging</string>
<string name="title_advanced_log_info">Debug logging</string> <string name="title_advanced_log_info">Debug logging</string>
<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_room_query_threads" translatable="false">ROOM query threads %1$s</string>
<string name="title_advanced_wal" translatable="false">WAL</string> <string name="title_advanced_wal" translatable="false">WAL</string>
<string name="title_advanced_checkpoints" translatable="false">Checkpoints</string> <string name="title_advanced_checkpoints" translatable="false">Checkpoints</string>
<string name="title_advanced_sqlite_cache" translatable="false">Sqlite cache %1$s %% - %2$s</string> <string name="title_advanced_sqlite_cache" translatable="false">Sqlite cache %1$s %% - %2$s</string>
@ -730,7 +730,6 @@
<string name="title_advanced_notify_no_grouping">This Android version does not support notification grouping</string> <string name="title_advanced_notify_no_grouping">This Android version does not support notification grouping</string>
<string name="title_advanced_notify_no_channels">This Android version does not support notification channels</string> <string name="title_advanced_notify_no_channels">This Android version does not support notification channels</string>
<string name="title_advanced_queries_hint">Enabling this will decrease performance, however, enabling is required on some devices</string>
<string name="title_advanced_fts_hint">Enabling this improves search performance, but also increases battery and storage space usage</string> <string name="title_advanced_fts_hint">Enabling this improves search performance, but also increases battery and storage space usage</string>
<string name="title_advanced_english_hint">This will restart the app</string> <string name="title_advanced_english_hint">This will restart the app</string>
<string name="title_advanced_experiments_hint">List of current experimental features</string> <string name="title_advanced_experiments_hint">List of current experimental features</string>

Loading…
Cancel
Save