perf: warm modern home startup rows
This commit is contained in:
parent
3d42da9d37
commit
0c2bb40707
2 changed files with 30 additions and 3 deletions
|
|
@ -218,6 +218,28 @@ internal fun HomeViewModel.observeModernHomePresentationPipeline() {
|
|||
}
|
||||
.distinctUntilChanged()
|
||||
.collectLatest { input ->
|
||||
val shouldWarmStart = uiState.value.modernHomePresentation.rows.isEmpty()
|
||||
val visibleCatalogRowCount = input.catalogRows.count { it.items.isNotEmpty() }
|
||||
val warmStartCatalogRowCount = if (input.continueWatchingItems.isNotEmpty()) 1 else 2
|
||||
|
||||
if (shouldWarmStart && visibleCatalogRowCount > warmStartCatalogRowCount) {
|
||||
val warmStartPresentation = withContext(Dispatchers.Default) {
|
||||
buildModernHomePresentation(
|
||||
input = input,
|
||||
cache = modernCarouselRowBuildCache,
|
||||
context = appContext,
|
||||
maxCatalogRows = warmStartCatalogRowCount
|
||||
)
|
||||
}
|
||||
_uiState.update { state ->
|
||||
if (state.modernHomePresentation == warmStartPresentation) {
|
||||
state
|
||||
} else {
|
||||
state.copy(modernHomePresentation = warmStartPresentation)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val presentation = withContext(Dispatchers.Default) {
|
||||
buildModernHomePresentation(
|
||||
input = input,
|
||||
|
|
|
|||
|
|
@ -17,9 +17,14 @@ internal data class ModernHomePresentationInput(
|
|||
internal fun buildModernHomePresentation(
|
||||
input: ModernHomePresentationInput,
|
||||
cache: ModernCarouselRowBuildCache,
|
||||
context: Context
|
||||
context: Context,
|
||||
maxCatalogRows: Int? = null
|
||||
): ModernHomePresentationState {
|
||||
val visibleCatalogRows = input.catalogRows.filter { it.items.isNotEmpty() }
|
||||
val catalogRowsToRender = maxCatalogRows
|
||||
?.coerceAtLeast(0)
|
||||
?.let(visibleCatalogRows::take)
|
||||
?: visibleCatalogRows
|
||||
val strContinueWatching = context.getString(R.string.continue_watching)
|
||||
val strAirsDate = context.getString(R.string.cw_airs_date)
|
||||
val strUpcoming = context.getString(R.string.cw_upcoming)
|
||||
|
|
@ -27,7 +32,7 @@ internal fun buildModernHomePresentation(
|
|||
val strTypeSeries = context.getString(R.string.type_series)
|
||||
|
||||
val rows = buildList {
|
||||
val activeCatalogKeys = LinkedHashSet<String>(visibleCatalogRows.size)
|
||||
val activeCatalogKeys = LinkedHashSet<String>(catalogRowsToRender.size)
|
||||
|
||||
if (input.continueWatchingItems.isNotEmpty()) {
|
||||
val reuseContinueWatchingRow =
|
||||
|
|
@ -67,7 +72,7 @@ internal fun buildModernHomePresentation(
|
|||
cache.continueWatchingRow = null
|
||||
}
|
||||
|
||||
visibleCatalogRows.forEachIndexed { index, row ->
|
||||
catalogRowsToRender.forEachIndexed { index, row ->
|
||||
val rowKey = catalogRowKey(row)
|
||||
activeCatalogKeys += rowKey
|
||||
val cached = cache.catalogRows[rowKey]
|
||||
|
|
|
|||
Loading…
Reference in a new issue