From 46c4f4d50173988cdceab8411fc4548478ababfa Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 29 Jun 2022 09:48:47 +1000 Subject: [PATCH] Fix slow browser load in new backend https://github.com/ankidroid/Anki-Android/pull/11644#issuecomment-1169380381 Closes #11733 --- .../main/java/com/ichi2/libanki/CollectionV16.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/CollectionV16.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/CollectionV16.kt index b627754326bb..dfb40f4e212c 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/CollectionV16.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/CollectionV16.kt @@ -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 @@ -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 { + if (task?.isCancelled() == true) { + return listOf() + } val adjustedOrder = if (order is SortOrder.UseCollectionOrdering) { @Suppress("DEPRECATION") SortOrder.BuiltinSortKind( @@ -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 }