]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- optimize collection of cols we insert as none
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 18 Aug 2014 21:12:06 +0000 (17:12 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 18 Aug 2014 21:15:04 +0000 (17:15 -0400)
lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/orm/persistence.py

index 14dc5d7f87e59557945956e4468d4339230f7652..89c092b580cc5f5921c2e9836627b4275d9ba0e8 100644 (file)
@@ -1894,27 +1894,27 @@ class Mapper(InspectionAttr):
     """
 
     @_memoized_configured_property
-    def _propkey_to_col(self):
+    def _insert_cols_as_none(self):
         return dict(
             (
                 table,
-                dict(
-                    (self._columntoproperty[col].key, col)
-                    for col in columns
-                )
+                frozenset(
+                    col.key for col in columns
+                    if not col.primary_key and
+                    not col.server_default and not col.default)
             )
             for table, columns in self._cols_by_table.items()
         )
 
     @_memoized_configured_property
-    def _col_to_propkey(self):
+    def _propkey_to_col(self):
         return dict(
             (
                 table,
-                [
-                    (col, self._columntoproperty[col].key)
+                dict(
+                    (self._columntoproperty[col].key, col)
                     for col in columns
-                ]
+                )
             )
             for table, columns in self._cols_by_table.items()
         )
index c949e47764ad8ba09f04d1649401b3923c996578..e36f87991d470cf1d6b971016c414fac7497995f 100644 (file)
@@ -282,14 +282,8 @@ def _collect_insert_commands(table, states_to_insert):
             else:
                 params[col.key] = value
 
-        for colkey in (
-            set(
-                col.key for col in
-                mapper._cols_by_table[table]
-                if not col.primary_key and
-                not col.server_default and not col.default
-            ).difference(params).difference(value_params)
-        ):
+        for colkey in mapper._insert_cols_as_none[table].\
+                difference(params).difference(value_params):
             params[colkey] = None
 
         has_all_pks = mapper._pk_keys_by_table[table].issubset(params)