From: Mike Bayer Date: Tue, 21 Mar 2006 02:43:58 +0000 (+0000) Subject: a refactoring to the EagerLoaders' _instance method to do a bunch of column arithmeti... X-Git-Tag: rel_0_1_5~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85bc3613e87001369bbcd68045dd5fa77acb0cbd;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git a refactoring to the EagerLoaders' _instance method to do a bunch of column arithmetic up front, instead of on each row --- diff --git a/lib/sqlalchemy/mapping/properties.py b/lib/sqlalchemy/mapping/properties.py index 6a073f0a6b..4d04997a65 100644 --- a/lib/sqlalchemy/mapping/properties.py +++ b/lib/sqlalchemy/mapping/properties.py @@ -758,6 +758,8 @@ class EagerLoader(PropertyLoader): for key, value in self.mapper.props.iteritems(): value.setup(key, statement, eagertable=self.eagertarget) + self._decorator_row = self._create_decorator_row() + def execute(self, instance, row, identitykey, imap, isnew): """receive a row. tell our mapper to look for a new object instance in the row, and attach it to a list on the parent instance.""" @@ -783,6 +785,21 @@ class EagerLoader(PropertyLoader): self._instance(row, imap, result_list) + def _create_decorator_row(self): + class DecoratorDict(object): + def __init__(self, row): + self.row = row + def __getitem__(self, key): + if map.has_key(key): + key = map[key] + return self.row[key] + map = {} + for c in self.eagertarget.c: + parent = self.target._get_col_by_original(c.original) + map[parent] = c + map[parent._label] = c + return DecoratorDict + def _instance(self, row, imap, result_list=None): """gets an instance from a row, via this EagerLoader's mapper.""" # since the EagerLoader makes an Alias of its mapper's table, @@ -792,12 +809,7 @@ class EagerLoader(PropertyLoader): # (neither do any MapperExtensions). The row is keyed off the Column object # (which is what mappers use) as well as its "label" (which might be what # user-defined code is using) - fakerow = util.DictDecorator(row) - for c in self.eagertarget.c: - parent = self.target._get_col_by_original(c.original) - fakerow[parent] = row[c] - fakerow[parent._label] = row[c] - row = fakerow + row = self._decorator_row(row) return self.mapper._instance(row, imap, result_list) class GenericOption(MapperOption):