From b2e50a0da20d97744210e6c2684734a31f7e3d17 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Thu, 23 Jan 2020 12:05:29 +0100
Subject: [PATCH] up
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Henrik tom Wörden <h.tomwoerden@indiscale.com>
---
 src/caosdb/apiutils.py | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/caosdb/apiutils.py b/src/caosdb/apiutils.py
index 63d966b1..42080386 100644
--- a/src/caosdb/apiutils.py
+++ b/src/caosdb/apiutils.py
@@ -34,7 +34,7 @@ from collections.abc import Iterable
 from subprocess import call
 
 from . import (BOOLEAN, DATETIME, DOUBLE, FILE, INTEGER, REFERENCE, TEXT,
-               TIMESPAN, get_config)
+               TIMESPAN, execute_query, get_config)
 from .common.models import (Container, Entity, File, Property, Query, Record,
                             RecordType)
 
@@ -657,3 +657,26 @@ def describe_diff(olddiff, newdiff, name=None, as_update=True):
                        "version of {}\n\n".format(name))+description
 
     return description
+
+
+def id_query(ids):
+    """ executes a query that returns entities purely based on whether their id
+    is in the supplied list of ids """
+    q = "FIND Entity with " + " OR ".join(["id={}".format(id) for id in ids])
+
+    return execute_query(q)
+
+
+def retrieve_multiple_entities(ids, step=20):
+    """
+    retrieve the entities with the ids in the supplied list.
+
+    Entities are retrieved via queries. Due to a limited length of the query,
+    the entities are retrieved in chunks of sive "step")
+    """
+    collection = Container()
+
+    for i in range(len(ids)//step+1):
+        collection.extend(id_query(ids[i*step:(i+1)*step]))
+
+    return collection
-- 
GitLab