diff --git a/src/caosdb/apiutils.py b/src/caosdb/apiutils.py index 63d966b1ec7b61265093215e174aac8be20c1b79..4208038618586e7b9d1d085ec072150f3fa47ce5 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