Skip to content

Commit

Permalink
Don't call revert() in _inject, since that requires another O(N) loop…
Browse files Browse the repository at this point in the history
… over the injected columns; fixup internal state here.

If we get a dict, ignore the keys and just loop over the columns inside.

Don't do an extra list comprehension into a dict in load(), we just strip that back to values in _inject.
  • Loading branch information
ieure committed Mar 24, 2010
1 parent b3d23fa commit 179ef38
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lazyboy/record.py
Expand Up @@ -168,11 +168,18 @@ def __delitem__(self, item):
def _inject(self, key, columns):
"""Inject columns into the record after they have been fetched.."""
self.key = key
if not isinstance(columns, dict):
columns = dict((col.name, col) for col in iter(columns))

self._original = columns
self.revert()
if isinstance(columns, dict):
columns = columns.itervalues()

self._original = {}
for col in columns:
self._original[col.name] = col
dict.__setitem__(self, col.name, col.value)

This comment has been minimized.

Copy link
@selam

selam Apr 3, 2010

if data loading with KeyRecordSet from an super column, col variable turns another iterable type and raise "AttributeError: 'generator' object has no attribute 'name'"


self._columns = copy.copy(self._original)
self._modified, self._deleted = {}, {}

return self

def _marshal(self):
Expand All @@ -189,11 +196,7 @@ def load(self, key, consistency=None):

self._clean()
consistency = consistency or self.consistency

columns = iterators.slice_iterator(key, consistency)

self._inject(key, dict([(column.name, column) for column in columns]))
return self
return self._inject(key, iterators.slice_iterator(key, consistency))

def save(self, consistency=None):
"""Save the record, returns self."""
Expand Down

0 comments on commit 179ef38

Please sign in to comment.