Optimize ListTranscriptions
- Jul 01, 2022
-
-
703a7cf9
-
Closes #480 (closed)
element
to a cached property, along with its permission checks, to remove two duplicate queries.element__image__server
when not using recursive
, since the element is never returned.recursive
to use a UNION
on the element IDs from ElementPath + the ID of the current element.
Q(element=element) | Q(element__in=…)
because that makes PostgreSQL ignore almost every index and start using nested loops.get_descending
, because it uses some unnecessary ordering and deduplication.ElementPath.element_id
and not Element.id
to avoid an unnecessary join.UNION ALL
and not just UNION
, to avoid an unnecessary cycle of sorting and deduplicating IDs.id::varchar
sort did not show any difference with a normal id
sort, so I left it there, but it does not seem to be as "inefficient" as what the comments say.This makes recursive ListTranscriptions up to 10 times faster on top-level folders of random corpora with many transcriptions.