From e8f18afd2823757632ef620214c3da3fdef8c7c7 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 4 Jan 2019 14:48:55 +0000 Subject: [PATCH] Run database actions low priority Why isn't this the default mr Google? --- app/src/main/java/eu/faircode/email/DB.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/eu/faircode/email/DB.java b/app/src/main/java/eu/faircode/email/DB.java index 2201df0583..5358290091 100644 --- a/app/src/main/java/eu/faircode/email/DB.java +++ b/app/src/main/java/eu/faircode/email/DB.java @@ -12,6 +12,8 @@ import org.json.JSONObject; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import javax.mail.Address; import javax.mail.internet.InternetAddress; @@ -79,6 +81,7 @@ public abstract class DB extends RoomDatabase { public abstract DaoLog log(); private static DB sInstance; + private static ExecutorService executor = Executors.newCachedThreadPool(Helper.backgroundThreadFactory); private static final String DB_NAME = "fairemail"; @@ -87,6 +90,7 @@ public abstract class DB extends RoomDatabase { sInstance = migrate(context, Room .databaseBuilder(context.getApplicationContext(), DB.class, DB_NAME) .openHelperFactory(new RequerySQLiteOpenHelperFactory()) + .setQueryExecutor(executor) .setJournalMode(JournalMode.WRITE_AHEAD_LOGGING)); Log.i("sqlite version=" + exec(sInstance, "SELECT sqlite_version() AS sqlite_version"));