perf(core): offload LunarCache precomputing and batch calculation to Dispatchers.Default
This commit is contained in:
parent
1b2fcfe248
commit
fc2f2065df
@ -3,6 +3,7 @@ package plus.rua.project
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
@ -81,7 +82,7 @@ class CalendarViewModel(
|
||||
getMonthGridInfo(normalizedYear, normalizedMonth)
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
viewModelScope.launch(Dispatchers.Default) {
|
||||
monthsToPrecompute.forEach { info ->
|
||||
val dates = (0 until info.totalDays).map { i ->
|
||||
info.startDate.plus(DatePeriod(days = i))
|
||||
|
||||
@ -33,6 +33,8 @@ import plus.rua.project.DayCellInfo
|
||||
import plus.rua.project.LunarCache
|
||||
import plus.rua.project.ShiftKind
|
||||
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
* 月度日历网格页面,支持两阶段折叠动画。
|
||||
@ -80,7 +82,9 @@ fun CalendarMonthPage(
|
||||
key1 = year,
|
||||
key2 = month
|
||||
) {
|
||||
value = LunarCache.default.getOrComputeBatch(days.map { it.date })
|
||||
value = withContext(Dispatchers.Default) {
|
||||
LunarCache.default.getOrComputeBatch(days.map { it.date })
|
||||
}
|
||||
}
|
||||
|
||||
val holidayEdges = remember(lunarDataMap, year, month) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user