From 112f81148071877a4bb549fbad4956b86cf5f691 Mon Sep 17 00:00:00 2001 From: Osmo Salomaa Date: Mon, 23 Oct 2023 22:52:15 +0300 Subject: [PATCH] Limit results returned per plugin Related to #23 --- NEWS.md | 6 ++++++ catapult/conf.py | 1 + catapult/search.py | 6 +++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 3069f2c..216997e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +PENDING: Catapult 1.0 +===================== + +* Limit results returned per plugin (default 24) to avoid issues with + huge file indexes paired with short query strings (#23) + 2023-08-31: Catapult 0.999 ========================== diff --git a/catapult/conf.py b/catapult/conf.py index 20a1fe6..2577f4d 100644 --- a/catapult/conf.py +++ b/catapult/conf.py @@ -49,6 +49,7 @@ class ConfigurationStore(catapult.DebugMixin): _defaults = { "max_results": 24, + "max_results_per_plugin": 24, "max_results_visible": 7, "plugins": ["apps", "builtins", "calculator", "clipboard", "files", "session"], "theme": "dark", diff --git a/catapult/search.py b/catapult/search.py index 581fc03..d7c4963 100644 --- a/catapult/search.py +++ b/catapult/search.py @@ -56,7 +56,11 @@ def _get_results(self, plugins, query): for plugin in plugins: self.tick() try: - yield from plugin.search(query) + for i, result in enumerate(plugin.search(query)): + yield result + if i + 1 >= catapult.conf.max_results_per_plugin: + self.debug(f"Terminating after {i+1} results") + break elapsed = self.tock() self.debug(f"{plugin.name} delivered in {elapsed:.0f} ms") except Exception: