mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-01 15:14:25 +02:00
perf(app): logger history cache
Signed-off-by: rhunk <101876869+rhunk@users.noreply.github.com>
This commit is contained in:
parent
a1dc03c958
commit
ebc5469fd0
@ -15,7 +15,6 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.focus.focusRequester
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.ui.text.font.FontStyle
|
import androidx.compose.ui.text.font.FontStyle
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
@ -48,6 +47,7 @@ import me.rhunk.snapenhance.download.DownloadProcessor
|
|||||||
import me.rhunk.snapenhance.storage.findFriend
|
import me.rhunk.snapenhance.storage.findFriend
|
||||||
import me.rhunk.snapenhance.ui.manager.Routes
|
import me.rhunk.snapenhance.ui.manager.Routes
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
|
|
||||||
@ -219,6 +219,8 @@ class LoggerHistoryRoot : Routes.Route() {
|
|||||||
loggerWrapper = LoggerWrapper(context.androidContext)
|
loggerWrapper = LoggerWrapper(context.androidContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val conversationInfoCache = remember { ConcurrentHashMap<String, String?>() }
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
@ -241,11 +243,15 @@ class LoggerHistoryRoot : Routes.Route() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val selectedConversationInfo by rememberAsyncMutableState(defaultValue = null, keys = arrayOf(selectedConversation)) {
|
val selectedConversationInfo by rememberAsyncMutableState(defaultValue = null, keys = arrayOf(selectedConversation)) {
|
||||||
selectedConversation?.let { loggerWrapper.getConversationInfo(it) }
|
selectedConversation?.let {
|
||||||
|
conversationInfoCache.getOrPut(it) {
|
||||||
|
formatConversationInfo(loggerWrapper.getConversationInfo(it))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = remember(selectedConversationInfo) { formatConversationInfo(selectedConversationInfo) ?: "Select a conversation" },
|
value = selectedConversationInfo ?: "Select a conversation",
|
||||||
onValueChange = {},
|
onValueChange = {},
|
||||||
readOnly = true,
|
readOnly = true,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -264,7 +270,9 @@ class LoggerHistoryRoot : Routes.Route() {
|
|||||||
expanded = false
|
expanded = false
|
||||||
}, text = {
|
}, text = {
|
||||||
val conversationInfo by rememberAsyncMutableState(defaultValue = null, keys = arrayOf(conversationId)) {
|
val conversationInfo by rememberAsyncMutableState(defaultValue = null, keys = arrayOf(conversationId)) {
|
||||||
formatConversationInfo(loggerWrapper.getConversationInfo(conversationId))
|
conversationInfoCache.getOrPut(conversationId) {
|
||||||
|
formatConversationInfo(loggerWrapper.getConversationInfo(conversationId))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
|
@ -399,14 +399,6 @@ class LoggerWrapper(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getConversationInfo(conversationId: String): ConversationInfo? {
|
fun getConversationInfo(conversationId: String): ConversationInfo? {
|
||||||
val participantSize = database.rawQuery("SELECT COUNT(DISTINCT user_id) FROM messages WHERE conversation_id = ?", arrayOf(conversationId)).use {
|
|
||||||
if (!it.moveToFirst()) return null
|
|
||||||
it.getInt(0)
|
|
||||||
}
|
|
||||||
val groupTitle = if (participantSize > 2) database.rawQuery("SELECT group_title FROM messages WHERE conversation_id = ? AND group_title IS NOT NULL LIMIT 1", arrayOf(conversationId)).use {
|
|
||||||
if (!it.moveToFirst()) return@use null
|
|
||||||
it.getStringOrNull("group_title")
|
|
||||||
} else null
|
|
||||||
val usernames = database.rawQuery("SELECT DISTINCT username FROM messages WHERE conversation_id = ?", arrayOf(conversationId)).use {
|
val usernames = database.rawQuery("SELECT DISTINCT username FROM messages WHERE conversation_id = ?", arrayOf(conversationId)).use {
|
||||||
val usernames = mutableListOf<String>()
|
val usernames = mutableListOf<String>()
|
||||||
while (it.moveToNext()) {
|
while (it.moveToNext()) {
|
||||||
@ -415,7 +407,14 @@ class LoggerWrapper(
|
|||||||
usernames
|
usernames
|
||||||
}
|
}
|
||||||
|
|
||||||
return ConversationInfo(conversationId, participantSize, groupTitle, usernames)
|
if (usernames.size > 2) { usernames.remove("myai") }
|
||||||
|
|
||||||
|
val groupTitle = if (usernames.size > 2) database.rawQuery("SELECT group_title FROM messages WHERE conversation_id = ? AND group_title IS NOT NULL LIMIT 1", arrayOf(conversationId)).use {
|
||||||
|
if (!it.moveToFirst()) return@use null
|
||||||
|
it.getStringOrNull("group_title")
|
||||||
|
} else null
|
||||||
|
|
||||||
|
return ConversationInfo(conversationId, usernames.size, groupTitle, usernames)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getChatEdits(conversationId: String, messageId: Long): List<LoggedChatEdit> {
|
override fun getChatEdits(conversationId: String, messageId: Long): List<LoggedChatEdit> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user