[saem-devel] [PATCH] [eac] Optimize query retrieving associated records

Sylvain Thenault sylvain.thenault at logilab.fr
Tue Jan 31 10:45:05 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1485855217 -3600
#      Tue Jan 31 10:33:37 2017 +0100
# Node ID a4314691c4258f28ed6cf7459e914f7ea5f687e0
# Parent  3062e3d0825f727a5aac07cc3ae90c88b7c588d7
[eac] Optimize query retrieving associated records

else the underlying view will to an extra query for *each* now-prefetched attribute,
which takes age when there are a few hundred associated entities.

diff --git a/cubicweb_saem_ref/views/authorityrecord.py b/cubicweb_saem_ref/views/authorityrecord.py
--- a/cubicweb_saem_ref/views/authorityrecord.py
+++ b/cubicweb_saem_ref/views/authorityrecord.py
@@ -687,12 +687,14 @@ class AuthorityRecordAssociationRelation
         has_related_entities('association_to', role='object'))
 
     def entity_call(self, entity, **kwargs):
         self.w(tags.h2(self._cw._('associated with')))
         rset = self._cw.execute(
-            '(Any X WHERE X association_from A, A eid %(eid)s) '
-            'UNION (Any X WHERE X association_to A, A eid %(eid)s)',
+            '(Any X,XD,XSD,XED,XAF,XAT WHERE X association_from XAF, XAF eid %(eid)s, '
+            'X description XD, X start_date XSD, X end_date XED, X association_to XAT) '
+            'UNION (Any X,XD,XSD,XED,XAF,XAT WHERE X association_to XAT, XAT eid %(eid)s, '
+            'X description XD, X start_date XSD, X end_date XED, X association_from XAF)',
             {'eid': entity.eid})
         self._cw.view('list', rset=rset, w=self.w,
                       subvid='saem_ref.associationrelation',
                       main_record=entity,
                       __redirectpath=entity.rest_path())


More information about the saem-devel mailing list