[repository] drop usage of no more necessary eschema_eid function
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 03 Feb 2016 14:23:17 +0100
changeset 11091 29aebc1edd29
parent 11090 b4b854c25de5
child 11092 3d177dfcdb19
[repository] drop usage of no more necessary eschema_eid function since the previous cset, we are guaranteed that repository's entity schema will have their eid attribute properly set, so we don't have anymore to check everytime if some entity schema's .eid attributes is set or not (and retrieve it if not). Related to #10450092
dataimport/pgstore.py
server/sources/native.py
server/utils.py
--- a/dataimport/pgstore.py	Thu Jan 28 18:17:30 2016 +0100
+++ b/dataimport/pgstore.py	Wed Feb 03 14:23:17 2016 +0100
@@ -30,7 +30,6 @@
 from six.moves import cPickle as pickle, range
 
 from cubicweb.utils import make_uid
-from cubicweb.server.utils import eschema_eid
 from cubicweb.server.sqlutils import SQL_PREFIX
 from cubicweb.dataimport.stores import NoHookRQLObjectStore
 
@@ -425,17 +424,12 @@
                  'asource': source.uri}
         self._handle_insert_entity_sql(cnx, self.sqlgen.insert('entities', attrs), attrs)
         # insert core relations: is, is_instance_of and cw_source
-        try:
-            self._handle_is_relation_sql(cnx, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)',
-                                         (entity.eid, eschema_eid(cnx, entity.e_schema)))
-        except IndexError:
-            # during schema serialization, skip
-            pass
-        else:
-            for eschema in entity.e_schema.ancestors() + [entity.e_schema]:
-                self._handle_is_relation_sql(cnx,
-                                             'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)',
-                                             (entity.eid, eschema_eid(cnx, eschema)))
+        self._handle_is_relation_sql(cnx, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)',
+                                     (entity.eid, entity.e_schema.eid))
+        for eschema in entity.e_schema.ancestors() + [entity.e_schema]:
+            self._handle_is_relation_sql(cnx,
+                                         'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)',
+                                         (entity.eid, eschema.eid))
         self._handle_is_relation_sql(cnx, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)',
                                      (entity.eid, source.eid))
         # now we can update the full text index
--- a/server/sources/native.py	Thu Jan 28 18:17:30 2016 +0100
+++ b/server/sources/native.py	Wed Feb 03 14:23:17 2016 +0100
@@ -56,7 +56,7 @@
 from cubicweb.cwconfig import CubicWebNoAppConfiguration
 from cubicweb.server import hook
 from cubicweb.server import schema2sql as y2sql
-from cubicweb.server.utils import crypt_password, eschema_eid, verify_and_update
+from cubicweb.server.utils import crypt_password, verify_and_update
 from cubicweb.server.sqlutils import SQL_PREFIX, SQLAdapterMixIn
 from cubicweb.server.rqlannotation import set_qdata
 from cubicweb.server.hook import CleanupDeletedEidsCacheOp
@@ -915,17 +915,14 @@
                  'asource': text_type(source.uri)}
         self._handle_insert_entity_sql(cnx, self.sqlgen.insert('entities', attrs), attrs)
         # insert core relations: is, is_instance_of and cw_source
-        try:
+
+        if entity.e_schema.eid is not None:  # else schema has not yet been serialized
             self._handle_is_relation_sql(cnx, 'INSERT INTO is_relation(eid_from,eid_to) VALUES (%s,%s)',
-                                         (entity.eid, eschema_eid(cnx, entity.e_schema)))
-        except IndexError:
-            # during schema serialization, skip
-            pass
-        else:
+                                         (entity.eid, entity.e_schema.eid))
             for eschema in entity.e_schema.ancestors() + [entity.e_schema]:
                 self._handle_is_relation_sql(cnx,
                                              'INSERT INTO is_instance_of_relation(eid_from,eid_to) VALUES (%s,%s)',
-                                             (entity.eid, eschema_eid(cnx, eschema)))
+                                             (entity.eid, eschema.eid))
         if 'CWSource' in self.schema and source.eid is not None: # else, cw < 3.10
             self._handle_is_relation_sql(cnx, 'INSERT INTO cw_source_relation(eid_from,eid_to) VALUES (%s,%s)',
                                          (entity.eid, source.eid))
--- a/server/utils.py	Thu Jan 28 18:17:30 2016 +0100
+++ b/server/utils.py	Wed Feb 03 14:23:17 2016 +0100
@@ -1,4 +1,4 @@
-# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -31,6 +31,8 @@
 from passlib.utils import handlers as uh, to_hash_str
 from passlib.context import CryptContext
 
+from logilab.common.deprecation import deprecated
+
 from cubicweb.md5crypt import crypt as md5crypt
 
 
@@ -76,16 +78,14 @@
     # wrong password
     return b''
 
-
+@deprecated('[3.22] no more necessary, directly get eschema.eid')
 def eschema_eid(cnx, eschema):
-    """get eid of the CWEType entity for the given yams type. You should use
-    this because when schema has been loaded from the file-system, not from the
-    database, (e.g. during tests), eschema.eid is not set.
+    """get eid of the CWEType entity for the given yams type.
+
+    This used to be necessary because when the schema has been loaded from the
+    file-system, not from the database, (e.g. during tests), eschema.eid was
+    not set.
     """
-    if eschema.eid is None:
-        eschema.eid = cnx.execute(
-            'Any X WHERE X is CWEType, X name %(name)s',
-            {'name': text_type(eschema)})[0][0]
     return eschema.eid