List transcriptions on an element and its children
Issue raised while implementing new workers that use a lot of transcriptions: https://notes.vpn/L8g67pfvSkuPekjPdL_CLw#
With the migration to transcriptions without zones, it becomes much slower to list all transcriptions on an element, since it requires listing all transcriptions on each child element of an element, recursively. This is rather slow since it can generate hundreds of API calls. However, on the backend side, we can easily list all transcriptions on an element and its children thanks to get_descending
.
GET /api/v1/element/<uuid>/transcriptions/?recursive=True
{
'count': 42,
'results': [
{
'id': '...',
'type': 'line',
'text': 'Lorem ipsum',
'score': 0.42,
'source': { ... },
'element': {
'id': '...',
'zone': {
'polygon': [...]
}
}
}
]
}
The serializer will need to be modified to add the element
field, but otherwise it is similar to what we already have. In terms of SQL, this implies changing Transcription.objects.filter(element_id=...)
into Transcription.objects.filter(Q(element_id=...) | Q(element__in=Element.objects.get_descending(...)))
, which is a similar pattern that we have in other endpoints.