Skip to content

Commit 8ef74f2

Browse files
committed
don't sort twice on startup, it's expensive
1 parent 42a829c commit 8ef74f2

File tree

1 file changed

+3
-1
lines changed
  • app/src/main/kotlin/org/akanework/gramophone/ui/adapters

1 file changed

+3
-1
lines changed

app/src/main/kotlin/org/akanework/gramophone/ui/adapters/BaseAdapter.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ import kotlinx.coroutines.NonCancellable
4747
import kotlinx.coroutines.cancel
4848
import kotlinx.coroutines.flow.Flow
4949
import kotlinx.coroutines.flow.MutableStateFlow
50+
import kotlinx.coroutines.flow.SharingStarted
5051
import kotlinx.coroutines.flow.combine
5152
import kotlinx.coroutines.flow.first
5253
import kotlinx.coroutines.flow.flatMapLatest
54+
import kotlinx.coroutines.flow.shareIn
5355
import kotlinx.coroutines.launch
5456
import kotlinx.coroutines.runBlocking
5557
import kotlinx.coroutines.sync.Semaphore
@@ -178,7 +180,7 @@ abstract class BaseAdapter<T>(
178180
}
179181
}
180182
}.toList()
181-
}
183+
}.shareIn(CoroutineScope(Dispatchers.Default), SharingStarted.WhileSubscribed(5000), replay = 1)
182184
val sortTypes: Set<Sorter.Type>
183185
get() = if (canSort) sorter.getSupportedTypes() else setOf(Sorter.Type.None)
184186

0 commit comments

Comments
 (0)