Commit d003f731 authored by Geoffrey Métais's avatar Geoffrey Métais

Speed up loading of large collections

parent 40b29b32
......@@ -183,13 +183,15 @@ object MediaUtils : CoroutineScope {
in 1..MEDIALIBRARY_PAGE_SIZE -> play(withContext(Dispatchers.IO) { model.getAll().toList() })
else -> {
var index = 0
val appendList = mutableListOf<MediaWrapper>()
while (index < count) {
val pageCount = min(MEDIALIBRARY_PAGE_SIZE, count - index)
val list = withContext(Dispatchers.IO) { model.getPage(pageCount, index).toList() }
if (index == 0) play(list)
else service.append(list)
else appendList.addAll(list)
index += pageCount
}
service.append(appendList)
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment