From 16669bafa2ed89e64d4069ce38eba3558a8eca00 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Wed, 13 Oct 2021 14:09:42 +0200 Subject: [PATCH 1/2] improve performance of `get_many` by making it use a different server REST API. It now uses the low-level document API instead of the `/_api/simple/lookup-by-keys` API. The former can be used as a drop-in replacement for the latter. --- arango/collection.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arango/collection.py b/arango/collection.py index 3bccb5ec..6f3b4803 100644 --- a/arango/collection.py +++ b/arango/collection.py @@ -993,19 +993,23 @@ def get_many(self, documents: Sequence[Union[str, Json]]) -> Result[List[Json]]: :raise arango.exceptions.DocumentGetError: If retrieval fails. """ handles = [self._extract_id(d) if isinstance(d, dict) else d for d in documents] + + params: Params = { + "onlyget": True + } request = Request( method="put", - endpoint="/_api/simple/lookup-by-keys", - data={"collection": self.name, "keys": handles}, + endpoint=f"/_api/document/{self.name}", + params=params, + data=handles, read=self.name, ) def response_handler(resp: Response) -> List[Json]: if not resp.is_success: raise DocumentGetError(resp, request) - docs = resp.body["documents"] - return [doc for doc in docs if "_id" in doc] + return [doc for doc in resp.body if "_id" in doc] return self._execute(request, response_handler) From 8b35fb4708837c4777d0fd01dfbd4314c053e481 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Wed, 13 Oct 2021 17:54:50 +0200 Subject: [PATCH 2/2] apply code formatting --- arango/collection.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arango/collection.py b/arango/collection.py index 6f3b4803..1d53b06e 100644 --- a/arango/collection.py +++ b/arango/collection.py @@ -993,10 +993,8 @@ def get_many(self, documents: Sequence[Union[str, Json]]) -> Result[List[Json]]: :raise arango.exceptions.DocumentGetError: If retrieval fails. """ handles = [self._extract_id(d) if isinstance(d, dict) else d for d in documents] - - params: Params = { - "onlyget": True - } + + params: Params = {"onlyget": True} request = Request( method="put",