diff --git a/api/api/views/media_views.py b/api/api/views/media_views.py index 8c33a295b33..906e5974700 100644 --- a/api/api/views/media_views.py +++ b/api/api/views/media_views.py @@ -105,6 +105,18 @@ def _get_request_serializer(self, request): return req_serializer def get_db_results(self, results): + """ + Map ES hits to ORM model instances. + + ORM instances have all necessary info needed for serializers whereas ES + hits only contain the subset of fields needed for indexing and search. + This function issues one query to the DB, using the ``identifier`` field + which is both unique and indexed, so it's quite performant. + + :param results: the list of ES hits + :return: the corresponding list of ORM model instances + """ + identifiers = [] hits = [] for hit in results: