[dataimport] drop massive store etype to eid index
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 28 Jan 2016 14:34:47 +0100
changeset 11317 4085a452b6b4
parent 11316 36c7cd362fc7
child 11318 09731bd52887
[dataimport] drop massive store etype to eid index and fix potential problem with is_instance_of relation insertion in case where the class of inserted entity has some (yams) parent.
cubicweb/dataimport/massive_store.py
--- a/cubicweb/dataimport/massive_store.py	Thu Jan 28 14:00:50 2016 +0100
+++ b/cubicweb/dataimport/massive_store.py	Thu Jan 28 14:34:47 2016 +0100
@@ -140,7 +140,6 @@
         if source is None:
             source = cnx.repo.system_source
         self.source = source
-        self._etype_eid_idx = dict(cnx.execute('Any XN,X WHERE X is CWEType, X name XN'))
 
     # INIT FUNCTIONS ########################################################
 
@@ -586,8 +585,10 @@
         self.metagen_push_relation(etype, self._cnx.user.eid, 'created_by_relation')
         self.metagen_push_relation(etype, self._cnx.user.eid, 'owned_by_relation')
         self.metagen_push_relation(etype, self.source.eid, 'cw_source_relation')
-        self.metagen_push_relation(etype, self._etype_eid_idx[etype], 'is_relation')
-        self.metagen_push_relation(etype, self._etype_eid_idx[etype], 'is_instance_of_relation')
+        eschema = self.schema[etype].eid
+        self.metagen_push_relation(etype, eschema.eid, 'is_relation')
+        for parent_eschema in eschema.ancestors() + [eschema]:
+            self.metagen_push_relation(etype, parent_eschema.eid, 'is_instance_of_relation')
         self.sql("INSERT INTO entities (eid, type, asource, extid) "
                  "SELECT cw_eid, '%s', 'system', NULL FROM cw_%s "
                  "WHERE NOT EXISTS (SELECT 1 FROM entities WHERE eid=cw_eid)"