Skip to content
Snippets Groups Projects
Commit e2c1047b authored by Eva Bardou's avatar Eva Bardou Committed by Bastien Abadie
Browse files

Retrieve transcriptions from local cache in list_transcriptions

parent 41204d06
No related branches found
No related tags found
No related merge requests found
......@@ -36,6 +36,8 @@ CachedTranscription = namedtuple(
def convert_table_tuple(table):
if table == "elements":
return CachedElement
elif table == "transcriptions":
return CachedTranscription
else:
raise NotImplementedError
......
......@@ -901,9 +901,30 @@ class ElementsWorker(BaseWorker):
), "worker_version should be of type str"
query_params["worker_version"] = worker_version
transcriptions = self.api_client.paginate(
"ListTranscriptions", id=element.id, **query_params
)
if self.cache and recursive is None:
# Checking that we only received query_params handled by the cache
assert set(query_params.keys()) <= {
"worker_version",
}, "When using the local cache, you can only filter by 'worker_version'"
conditions = [("element_id", "=", convert_str_uuid_to_hex(element.id))]
if worker_version:
conditions.append(
("worker_version_id", "=", convert_str_uuid_to_hex(worker_version))
)
transcriptions = self.cache.fetch(
"transcriptions",
where=conditions,
)
else:
if self.cache:
logger.warning(
"'recursive' filter was set, results will be retrieved from the API since the local cache doesn't handle this filter."
)
transcriptions = self.api_client.paginate(
"ListTranscriptions", id=element.id, **query_params
)
return transcriptions
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment