mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-03 01:17:41 +08:00
优化:避免 Room 主线程查询缓存 #345
This commit is contained in:
parent
7129de4a55
commit
2eda4f567b
@ -2,7 +2,9 @@ package com.idormy.sms.forwarder.database.dao
|
||||
|
||||
import androidx.paging.PagingSource
|
||||
import androidx.room.*
|
||||
import androidx.sqlite.db.SupportSQLiteQuery
|
||||
import com.idormy.sms.forwarder.database.entity.Frpc
|
||||
import com.idormy.sms.forwarder.database.entity.Sender
|
||||
import io.reactivex.Single
|
||||
|
||||
@Dao
|
||||
@ -33,9 +35,9 @@ interface FrpcDao {
|
||||
@Query("SELECT * FROM Frpc ORDER BY time DESC")
|
||||
fun pagingSource(): PagingSource<Int, Frpc>
|
||||
|
||||
//TODO:允许主线程访问,后面再优化
|
||||
@Query("SELECT * FROM Frpc ORDER BY time ASC")
|
||||
fun getAll(): List<Frpc>
|
||||
@Transaction
|
||||
@RawQuery(observedEntities = [Frpc::class])
|
||||
fun getAllRaw(query: SupportSQLiteQuery): List<Frpc>
|
||||
|
||||
@Query("DELETE FROM Frpc")
|
||||
fun deleteAll()
|
||||
|
@ -2,8 +2,8 @@ package com.idormy.sms.forwarder.database.dao
|
||||
|
||||
import androidx.paging.PagingSource
|
||||
import androidx.room.*
|
||||
import androidx.sqlite.db.SupportSQLiteQuery
|
||||
import com.idormy.sms.forwarder.database.entity.Rule
|
||||
//import com.idormy.sms.forwarder.database.entity.RuleAndSender
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Single
|
||||
|
||||
@ -34,29 +34,15 @@ interface RuleDao {
|
||||
@Query("SELECT count(*) FROM Rule where type=:type and status=:status")
|
||||
fun count(type: String, status: Int): Single<Int>
|
||||
|
||||
/*@Query(
|
||||
"SELECT Rule.*," +
|
||||
"Sender.name as sender_name,Sender.type as sender_type" +
|
||||
" FROM Rule" +
|
||||
" LEFT JOIN Sender ON Rule.sender_id = Sender.id" +
|
||||
" where Rule.type=:type" +
|
||||
" ORDER BY Rule.time DESC"
|
||||
)
|
||||
fun pagingSource(type: String): PagingSource<Int, Rule>*/
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM Rule where type=:type ORDER BY id DESC")
|
||||
fun pagingSource(type: String): PagingSource<Int, Rule>
|
||||
|
||||
//@Transaction
|
||||
//@Query("SELECT * FROM Rule where type=:type and status=:status and (sim_slot='ALL' or sim_slot=:simSlot)")
|
||||
//suspend fun getRuleAndSender(type: String, status: Int, simSlot: String): List<RuleAndSender>
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM Rule where type=:type and status=:status and (sim_slot='ALL' or sim_slot=:simSlot)")
|
||||
fun getRuleList(type: String, status: Int, simSlot: String): List<Rule>
|
||||
|
||||
//TODO:允许主线程访问,后面再优化
|
||||
@Query("SELECT * FROM Rule ORDER BY id ASC")
|
||||
fun getAll(): List<Rule>
|
||||
@Transaction
|
||||
@RawQuery(observedEntities = [Rule::class])
|
||||
fun getAllRaw(query: SupportSQLiteQuery): List<Rule>
|
||||
}
|
@ -2,6 +2,7 @@ package com.idormy.sms.forwarder.database.dao
|
||||
|
||||
import androidx.paging.PagingSource
|
||||
import androidx.room.*
|
||||
import androidx.sqlite.db.SupportSQLiteQuery
|
||||
import com.idormy.sms.forwarder.database.entity.Sender
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Single
|
||||
@ -37,14 +38,13 @@ interface SenderDao {
|
||||
@Query("SELECT * FROM Sender ORDER BY id DESC")
|
||||
fun getAll(): Single<List<Sender>>
|
||||
|
||||
@Transaction
|
||||
@RawQuery(observedEntities = [Sender::class])
|
||||
fun getAllRaw(query: SupportSQLiteQuery): List<Sender>
|
||||
|
||||
@Query("SELECT COUNT(id) FROM Sender WHERE status = 1")
|
||||
fun getOnCount(): Flow<Long>
|
||||
|
||||
//TODO:允许主线程访问,后面再优化
|
||||
@Query("SELECT * FROM Sender ORDER BY id ASC")
|
||||
fun getAll2(): List<Sender>
|
||||
|
||||
@Query("DELETE FROM Sender")
|
||||
fun deleteAll()
|
||||
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
package com.idormy.sms.forwarder.database.repository
|
||||
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.sqlite.db.SimpleSQLiteQuery
|
||||
import com.idormy.sms.forwarder.database.dao.FrpcDao
|
||||
import com.idormy.sms.forwarder.database.entity.Frpc
|
||||
import com.idormy.sms.forwarder.database.entity.Sender
|
||||
|
||||
class FrpcRepository(
|
||||
private val frpcDao: FrpcDao,
|
||||
) {
|
||||
|
||||
//var listener: Listener? = null
|
||||
|
||||
@WorkerThread
|
||||
fun insert(frpc: Frpc) {
|
||||
frpcDao.insert(frpc)
|
||||
@ -26,8 +26,10 @@ class FrpcRepository(
|
||||
@WorkerThread
|
||||
fun update(frpc: Frpc) = frpcDao.update(frpc)
|
||||
|
||||
//TODO:允许主线程访问,后面再优化
|
||||
val all: List<Frpc> = frpcDao.getAll()
|
||||
fun getAllNonCache(): List<Frpc> {
|
||||
val query = SimpleSQLiteQuery("SELECT * FROM Frpc ORDER BY time DESC")
|
||||
return frpcDao.getAllRaw(query)
|
||||
}
|
||||
|
||||
fun deleteAll() {
|
||||
frpcDao.deleteAll()
|
||||
|
@ -1,8 +1,10 @@
|
||||
package com.idormy.sms.forwarder.database.repository
|
||||
|
||||
import androidx.annotation.WorkerThread
|
||||
import androidx.sqlite.db.SimpleSQLiteQuery
|
||||
import com.idormy.sms.forwarder.database.dao.RuleDao
|
||||
import com.idormy.sms.forwarder.database.entity.Rule
|
||||
import com.idormy.sms.forwarder.database.entity.Sender
|
||||
|
||||
class RuleRepository(
|
||||
private val ruleDao: RuleDao,
|
||||
@ -27,15 +29,15 @@ class RuleRepository(
|
||||
@WorkerThread
|
||||
fun getOne(id: Long) = ruleDao.getOne(id)
|
||||
|
||||
//suspend fun getRuleAndSender(type: String, status: Int, simSlot: String) = ruleDao.getRuleAndSender(type, status, simSlot)
|
||||
|
||||
fun getRuleList(type: String, status: Int, simSlot: String) = ruleDao.getRuleList(type, status, simSlot)
|
||||
|
||||
@WorkerThread
|
||||
fun update(rule: Rule) = ruleDao.update(rule)
|
||||
|
||||
//TODO:允许主线程访问,后面再优化
|
||||
val all: List<Rule> = ruleDao.getAll()
|
||||
fun getAllNonCache(): List<Rule> {
|
||||
val query = SimpleSQLiteQuery("SELECT * FROM Rule ORDER BY id ASC")
|
||||
return ruleDao.getAllRaw(query)
|
||||
}
|
||||
|
||||
fun deleteAll() {
|
||||
ruleDao.deleteAll()
|
||||
|
@ -4,6 +4,7 @@ import androidx.annotation.WorkerThread
|
||||
import com.idormy.sms.forwarder.database.dao.SenderDao
|
||||
import com.idormy.sms.forwarder.database.entity.Sender
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import androidx.sqlite.db.SimpleSQLiteQuery
|
||||
|
||||
class SenderRepository(private val senderDao: SenderDao) {
|
||||
|
||||
@ -24,13 +25,14 @@ class SenderRepository(private val senderDao: SenderDao) {
|
||||
|
||||
fun update(sender: Sender) = senderDao.update(sender)
|
||||
|
||||
val count: Flow<Long> = senderDao.getOnCount()
|
||||
fun getAllNonCache(): List<Sender> {
|
||||
val query = SimpleSQLiteQuery("SELECT * FROM Sender ORDER BY id ASC")
|
||||
return senderDao.getAllRaw(query)
|
||||
}
|
||||
|
||||
//TODO:允许主线程访问,后面再优化
|
||||
val all: List<Sender> = senderDao.getAll2()
|
||||
val count: Flow<Long> = senderDao.getOnCount()
|
||||
|
||||
fun deleteAll() {
|
||||
senderDao.deleteAll()
|
||||
}
|
||||
|
||||
}
|
@ -46,7 +46,7 @@ import java.util.*
|
||||
@Page(name = "一键换新机")
|
||||
class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickListener {
|
||||
|
||||
val TAG: String = SmsQueryFragment::class.java.simpleName
|
||||
val TAG: String = CloneFragment::class.java.simpleName
|
||||
private var backupPath: String? = null
|
||||
private val backupFile = "SmsForwarder.json"
|
||||
private var pushCountDownHelper: CountDownButtonHelper? = null
|
||||
@ -171,6 +171,7 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
|
||||
FileUtils.createFileByDeleteOldFile(file)
|
||||
val cloneInfo = HttpServerUtils.exportSettings()
|
||||
val jsonStr = Gson().toJson(cloneInfo)
|
||||
Log.d(TAG, "jsonStr = $jsonStr")
|
||||
if (FileIOUtils.writeFileFromString(file, jsonStr)) {
|
||||
XToastUtils.success(getString(R.string.export_succeeded))
|
||||
} else {
|
||||
@ -273,6 +274,7 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
|
||||
}
|
||||
postRequest.upString(requestMsg)
|
||||
}
|
||||
|
||||
3 -> {
|
||||
try {
|
||||
val sm4Key = ConvertTools.hexStringToByteArray(HttpServerUtils.clientSignKey)
|
||||
@ -287,6 +289,7 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
|
||||
}
|
||||
postRequest.upString(requestMsg)
|
||||
}
|
||||
|
||||
else -> {
|
||||
postRequest.upJson(requestMsg)
|
||||
}
|
||||
@ -372,6 +375,7 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
|
||||
}
|
||||
postRequest.upString(requestMsg)
|
||||
}
|
||||
|
||||
3 -> {
|
||||
try {
|
||||
val sm4Key = ConvertTools.hexStringToByteArray(HttpServerUtils.clientSignKey)
|
||||
@ -386,6 +390,7 @@ class CloneFragment : BaseFragment<FragmentClientCloneBinding?>(), View.OnClickL
|
||||
}
|
||||
postRequest.upString(requestMsg)
|
||||
}
|
||||
|
||||
else -> {
|
||||
postRequest.upJson(requestMsg)
|
||||
}
|
||||
|
@ -145,9 +145,9 @@ class HttpServerUtils private constructor() {
|
||||
cloneInfo.versionCode = AppUtils.getAppVersionCode()
|
||||
cloneInfo.versionName = AppUtils.getAppVersionName()
|
||||
cloneInfo.settings = SharedPreference.exportPreference()
|
||||
cloneInfo.senderList = Core.sender.all
|
||||
cloneInfo.ruleList = Core.rule.all
|
||||
cloneInfo.frpcList = Core.frpc.all
|
||||
cloneInfo.senderList = Core.sender.getAllNonCache()
|
||||
cloneInfo.ruleList = Core.rule.getAllNonCache()
|
||||
cloneInfo.frpcList = Core.frpc.getAllNonCache()
|
||||
return cloneInfo
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user