]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
inlining
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 19 May 2014 21:43:54 +0000 (17:43 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 19 May 2014 21:43:54 +0000 (17:43 -0400)
lib/sqlalchemy/orm/instrumentation.py
lib/sqlalchemy/orm/loading.py
lib/sqlalchemy/orm/state.py

index 68b4f06115616c7e2253dfe70ab27afc5c19f9f3..7699e0578677b07a7d60395cd1365a3d7fe13ade 100644 (file)
@@ -288,12 +288,14 @@ class ClassManager(dict):
     def new_instance(self, state=None):
         instance = self.class_.__new__(self.class_)
         setattr(instance, self.STATE_ATTR,
-                    state or self._state_constructor(instance, self))
+                    self._state_constructor(instance, self)
+                        if not state else state)
         return instance
 
     def setup_instance(self, instance, state=None):
         setattr(instance, self.STATE_ATTR,
-                    state or self._state_constructor(instance, self))
+                    self._state_constructor(instance, self)
+                        if not state else state)
 
     def teardown_instance(self, instance):
         delattr(instance, self.STATE_ATTR)
index 8fcace9be1226a77aba20c93222cd3291ee05a40..7ea54d4cd0569b94aad59fa21502c2cf6e857ed5 100644 (file)
@@ -318,10 +318,8 @@ def instance_processor(mapper, context, path, adapter,
     append_result = listeners.append_result or None
     populate_existing = context.populate_existing or mapper.always_refresh
     invoke_all_eagers = context.invoke_all_eagers
-
     load_evt = mapper.class_manager.dispatch.load or None
     refresh_evt = mapper.class_manager.dispatch.refresh or None
-
     instance_state = attributes.instance_state
     instance_dict = attributes.instance_dict
 
@@ -335,8 +333,7 @@ def instance_processor(mapper, context, path, adapter,
             _populators(mapper, context, path, row, adapter,
                             new_populators,
                             existing_populators,
-                            eager_populators
-            )
+                            eager_populators)
 
         if translate_row:
             for fn in translate_row:
@@ -490,7 +487,7 @@ def instance_processor(mapper, context, path, adapter,
                 if key not in state.unloaded:
                     pop(state, dict_, row)
 
-            if isnew:
+            if isnew and refresh_evt:
                 state.manager.dispatch.refresh(state, context, attrs)
 
         if result is not None:
index 768b73c21e90e40dbd72110993e55a454734fe7c..7ff243e3b37e7a6436b7b0495e36dfb7db7e9ff1 100644 (file)
@@ -56,6 +56,8 @@ class InstanceState(interfaces._InspectionAttr):
     expired = False
     deleted = False
     _load_pending = False
+    committed_state = util.immutabledict()
+    callables = util.immutabledict()
 
     is_instance = True
 
@@ -63,8 +65,14 @@ class InstanceState(interfaces._InspectionAttr):
         self.class_ = obj.__class__
         self.manager = manager
         self.obj = weakref.ref(obj, self._cleanup)
-        self.callables = {}
-        self.committed_state = {}
+
+    @util.memoized_property
+    def callables(self):
+        return {}
+
+    @util.memoized_property
+    def committed_state(self):
+        return {}
 
     @util.memoized_property
     def attrs(self):
@@ -222,7 +230,8 @@ class InstanceState(interfaces._InspectionAttr):
         if instance_dict:
             instance_dict.discard(self)
 
-        self.callables = {}
+        if 'callables' in self.__dict__:
+            del self.callables
         self.session_id = self._strong_obj = None
         del self.obj
 
@@ -555,17 +564,19 @@ class InstanceState(interfaces._InspectionAttr):
 
     @classmethod
     def _commit_all_states(self, iter, instance_dict=None):
-        """Mass version of commit_all()."""
+        """Mass / highly inlined version of commit_all()."""
 
         for state, dict_ in iter:
-            state.committed_state.clear()
+            state_dict = state.__dict__
+
+            if 'committed_state' in state_dict:
+                del state_dict['committed_state']
 
-            # inline of:
-            # InstanceState._pending_mutations._reset(state)
-            state.__dict__.pop('_pending_mutations', None)
+            if '_pending_mutations' in state_dict:
+                del state_dict['_pending_mutations']
 
-            callables = state.callables
-            if callables:
+            if 'callables' in state_dict:
+                callables = state.callables
                 for key in list(callables):
                     if key in dict_ and callables[key] is state:
                         del callables[key]