Skip to content

Commit

Permalink
Fix slow browser load in new backend
Browse files Browse the repository at this point in the history
  • Loading branch information
dae authored and mikehardy committed Jul 22, 2022
1 parent 54c8426 commit 46c4f4d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/libanki/CollectionV16.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.ichi2.libanki

import android.content.Context
import com.ichi2.async.CancelListener.Companion.isCancelled
import com.ichi2.async.CollectionTask
import com.ichi2.libanki.backend.*
import com.ichi2.libanki.backend.model.toProtoBuf
Expand Down Expand Up @@ -93,11 +94,15 @@ class CollectionV16(
return TemplateManager.TemplateRenderContext.from_existing_card(c, browser).render()
}

@RustCleanup("drop the PartialSearch handling in the browse screen, which slows things down")
override fun findCards(
search: String,
order: SortOrder,
task: CollectionTask.PartialSearch?
): List<Long> {
if (task?.isCancelled() == true) {
return listOf()
}
val adjustedOrder = if (order is SortOrder.UseCollectionOrdering) {
@Suppress("DEPRECATION")
SortOrder.BuiltinSortKind(
Expand All @@ -112,8 +117,12 @@ class CollectionV16(
} catch (e: BackendInvalidInputException) {
throw InvalidSearchException(e)
}

task?.doProgress(cardIdsList)
for (id in cardIdsList) {
if (task?.isCancelled() == true) {
break
}
task?.doProgress(listOf(id))
}
return cardIdsList
}

Expand Down

0 comments on commit 46c4f4d

Please sign in to comment.