Commit e6d3c557 authored by Mygod's avatar Mygod

Reduce thread pool nos

parent ae222a10
...@@ -53,6 +53,8 @@ import com.google.firebase.analytics.FirebaseAnalytics ...@@ -53,6 +53,8 @@ import com.google.firebase.analytics.FirebaseAnalytics
import io.fabric.sdk.android.Fabric import io.fabric.sdk.android.Fabric
import kotlinx.coroutines.DEBUG_PROPERTY_NAME import kotlinx.coroutines.DEBUG_PROPERTY_NAME
import kotlinx.coroutines.DEBUG_PROPERTY_VALUE_ON import kotlinx.coroutines.DEBUG_PROPERTY_VALUE_ON
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
import kotlin.reflect.KClass import kotlin.reflect.KClass
...@@ -105,7 +107,10 @@ object Core { ...@@ -105,7 +107,10 @@ object Core {
System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON) System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON)
Fabric.with(deviceStorage, Crashlytics()) // multiple processes needs manual set-up Fabric.with(deviceStorage, Crashlytics()) // multiple processes needs manual set-up
FirebaseApp.initializeApp(deviceStorage) FirebaseApp.initializeApp(deviceStorage)
WorkManager.initialize(deviceStorage, Configuration.Builder().build()) WorkManager.initialize(deviceStorage, Configuration.Builder().apply {
setExecutor { GlobalScope.launch { it.run() } }
setTaskExecutor { GlobalScope.launch { it.run() } }
}.build())
// handle data restored/crash // handle data restored/crash
if (Build.VERSION.SDK_INT >= 24 && DataStore.directBootAware && if (Build.VERSION.SDK_INT >= 24 && DataStore.directBootAware &&
......
...@@ -28,21 +28,24 @@ import androidx.sqlite.db.SupportSQLiteDatabase ...@@ -28,21 +28,24 @@ import androidx.sqlite.db.SupportSQLiteDatabase
import com.github.shadowsocks.Core.app import com.github.shadowsocks.Core.app
import com.github.shadowsocks.database.migration.RecreateSchemaMigration import com.github.shadowsocks.database.migration.RecreateSchemaMigration
import com.github.shadowsocks.utils.Key import com.github.shadowsocks.utils.Key
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@Database(entities = [Profile::class, KeyValuePair::class], version = 28) @Database(entities = [Profile::class, KeyValuePair::class], version = 28)
abstract class PrivateDatabase : RoomDatabase() { abstract class PrivateDatabase : RoomDatabase() {
companion object { companion object {
private val instance by lazy { private val instance by lazy {
Room.databaseBuilder(app, PrivateDatabase::class.java, Key.DB_PROFILE) Room.databaseBuilder(app, PrivateDatabase::class.java, Key.DB_PROFILE).apply {
.addMigrations( addMigrations(
Migration26, Migration26,
Migration27, Migration27,
Migration28 Migration28
) )
.enableMultiInstanceInvalidation() allowMainThreadQueries()
.fallbackToDestructiveMigration() enableMultiInstanceInvalidation()
.allowMainThreadQueries() fallbackToDestructiveMigration()
.build() setQueryExecutor { GlobalScope.launch { it.run() } }
}.build()
} }
val profileDao get() = instance.profileDao() val profileDao get() = instance.profileDao()
......
...@@ -26,19 +26,22 @@ import androidx.room.RoomDatabase ...@@ -26,19 +26,22 @@ import androidx.room.RoomDatabase
import com.github.shadowsocks.Core import com.github.shadowsocks.Core
import com.github.shadowsocks.database.migration.RecreateSchemaMigration import com.github.shadowsocks.database.migration.RecreateSchemaMigration
import com.github.shadowsocks.utils.Key import com.github.shadowsocks.utils.Key
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@Database(entities = [KeyValuePair::class], version = 3) @Database(entities = [KeyValuePair::class], version = 3)
abstract class PublicDatabase : RoomDatabase() { abstract class PublicDatabase : RoomDatabase() {
companion object { companion object {
private val instance by lazy { private val instance by lazy {
Room.databaseBuilder(Core.deviceStorage, PublicDatabase::class.java, Key.DB_PUBLIC) Room.databaseBuilder(Core.deviceStorage, PublicDatabase::class.java, Key.DB_PUBLIC).apply {
.allowMainThreadQueries() addMigrations(
.addMigrations(
Migration3 Migration3
) )
.enableMultiInstanceInvalidation() allowMainThreadQueries()
.fallbackToDestructiveMigration() enableMultiInstanceInvalidation()
.build() fallbackToDestructiveMigration()
setQueryExecutor { GlobalScope.launch { it.run() } }
}.build()
} }
val kvPairDao get() = instance.keyValuePairDao() val kvPairDao get() = instance.keyValuePairDao()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment