diff --git a/pandora/annotation/models.py b/pandora/annotation/models.py index 24d2871e..51b08770 100644 --- a/pandora/annotation/models.py +++ b/pandora/annotation/models.py @@ -209,19 +209,15 @@ class Annotation(models.Model): def _get_entity_json(self, user=None, entity_cache=None): """When serializing many annotations pointing to the same entity, it is expensive to repeatedly look up and serialize the same entity. - - TODO: if Entity were a (nullable) foreign key of Annotation, we could just: - - prefetch_related('entity', 'entity__user', 'entity__documents') - - before serializing the annotations, which would make self.entity.json(user=user) cheap and - all this unnecessary. """ + from entity.models import Entity + if entity_cache is not None and self.value in entity_cache: return entity_cache[self.value] - entity = self.get_entity() - entity_json = entity.json(user=user) + id = ox.fromAZ(self.value) + entity = Entity.objects.filter(id=id).only('name').get() + entity_json = entity.json(keys=['id', 'name']) value = entity.annotation_value() if entity_cache is not None: