From d8e91d058cd494dfb7812994796d1a46eb532f6b Mon Sep 17 00:00:00 2001 From: moson-mo Date: Thu, 22 Dec 2022 12:41:29 +0100 Subject: [PATCH] fix(rpc): provides search should return name match We need to return packages matching on the name as well. (A package always provides itself) Signed-off-by: moson-mo --- aurweb/rpc.py | 12 +++++++++++- test/test_rpc.py | 13 +++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/aurweb/rpc.py b/aurweb/rpc.py index 2aa27500..1440703a 100644 --- a/aurweb/rpc.py +++ b/aurweb/rpc.py @@ -376,8 +376,18 @@ class RPC: search.search_by(by, arg) max_results = config.getint("options", "max_rpc_results") - results = self.entities(search.results()).limit(max_results + 1).all() + query = self.entities(search.results()).limit(max_results + 1) + + # For "provides", we need to union our relation search + # with an exact search since a package always provides itself. + # Turns out that doing this with an OR statement is extremely slow + if by == "provides": + search = RPCSearch() + search._search_by_exact_name(arg) + query = query.union(self.entities(search.results())) + + results = query.all() if len(results) > max_results: raise RPCError("Too many package results.") diff --git a/test/test_rpc.py b/test/test_rpc.py index 04efd38f..92714ff1 100644 --- a/test/test_rpc.py +++ b/test/test_rpc.py @@ -920,6 +920,19 @@ def test_rpc_search_provides( assert result.get("Name") == packages[0].Name +def test_rpc_search_provides_self( + client: TestClient, packages: list[Package], relations: list[PackageRelation] +): + params = {"v": 5, "type": "search", "by": "provides", "arg": "big-chungus"} + with client as request: + response = request.get("/rpc", params=params) + data = response.json() + # expected to return "big-chungus" + assert data.get("resultcount") == 1 + result = data.get("results")[0] + assert result.get("Name") == packages[0].Name + + def test_rpc_search_conflicts( client: TestClient, packages: list[Package], relations: list[PackageRelation] ):