From c2d45b415098687c503669d5139b42fd9480a90b Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 2 Jun 2022 21:47:13 +0800 Subject: [PATCH] Add query limit --- .../src/main/kotlin/me/shedaniel/linkie/web/LinkieWebServer.kt | 2 +- .../main/kotlin/me/shedaniel/linkie/web/MappingsQueryUtils.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/main/kotlin/me/shedaniel/linkie/web/LinkieWebServer.kt b/backend/src/main/kotlin/me/shedaniel/linkie/web/LinkieWebServer.kt index 2a01e9e..2b178fd 100644 --- a/backend/src/main/kotlin/me/shedaniel/linkie/web/LinkieWebServer.kt +++ b/backend/src/main/kotlin/me/shedaniel/linkie/web/LinkieWebServer.kt @@ -151,7 +151,7 @@ fun main() { if (allowClasses) add(MappingsEntryType.CLASS) if (allowMethods) add(MappingsEntryType.METHOD) if (allowFields) add(MappingsEntryType.FIELD) - }.toTypedArray()) + }.toTypedArray(), limit = limit) Thread.sleep(1000) call.respond( SearchResultEntries( diff --git a/backend/src/main/kotlin/me/shedaniel/linkie/web/MappingsQueryUtils.kt b/backend/src/main/kotlin/me/shedaniel/linkie/web/MappingsQueryUtils.kt index d420f1f..4a6cc3a 100644 --- a/backend/src/main/kotlin/me/shedaniel/linkie/web/MappingsQueryUtils.kt +++ b/backend/src/main/kotlin/me/shedaniel/linkie/web/MappingsQueryUtils.kt @@ -18,11 +18,12 @@ object MappingsQueryUtils { val fuzzy: Boolean, ) - suspend fun query(mappings: MappingsContainer, searchTerm: String, vararg types: MappingsEntryType): Result { + suspend fun query(mappings: MappingsContainer, searchTerm: String, vararg types: MappingsEntryType, limit: Int): Result { require(types.isNotEmpty()) val context = QueryContext( provider = { mappings }, searchKey = searchTerm, + limit = limit.toLong(), ) val result: MutableList> = mutableListOf() var classes: ClassResultList? = null