summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-05-19 17:43:54 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-05-19 17:43:54 -0400
commit665eced208b9e277f4b5cdb64f5ef0613938e11a (patch)
tree6a288a531fe928e0f910ab2a56f37fbef7bc7b90 /lib/sqlalchemy
parentfd57a4116301c91a651e397f65235bc6a766a39d (diff)
downloadsqlalchemy-665eced208b9e277f4b5cdb64f5ef0613938e11a.tar.gz
inlining
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/instrumentation.py6
-rw-r--r--lib/sqlalchemy/orm/loading.py7
-rw-r--r--lib/sqlalchemy/orm/state.py31
3 files changed, 27 insertions, 17 deletions
diff --git a/lib/sqlalchemy/orm/instrumentation.py b/lib/sqlalchemy/orm/instrumentation.py
index 68b4f0611..7699e0578 100644
--- a/lib/sqlalchemy/orm/instrumentation.py
+++ b/lib/sqlalchemy/orm/instrumentation.py
@@ -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)
diff --git a/lib/sqlalchemy/orm/loading.py b/lib/sqlalchemy/orm/loading.py
index 8fcace9be..7ea54d4cd 100644
--- a/lib/sqlalchemy/orm/loading.py
+++ b/lib/sqlalchemy/orm/loading.py
@@ -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:
diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py
index 768b73c21..7ff243e3b 100644
--- a/lib/sqlalchemy/orm/state.py
+++ b/lib/sqlalchemy/orm/state.py
@@ -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]