Rev 3780: Teach CHKInventory with a parent_id_basename index how to load partial index contents. in http://people.ubuntu.com/~robertc/baz2.0/repository
Robert Collins
robertc at robertcollins.net
Fri Nov 14 03:36:38 GMT 2008
At http://people.ubuntu.com/~robertc/baz2.0/repository
------------------------------------------------------------
revno: 3780
revision-id: robertc at robertcollins.net-20081114033634-9ns1w15wx9f17tpk
parent: robertc at robertcollins.net-20081114032957-uqh1lsxe0s21vt8x
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Fri 2008-11-14 14:36:34 +1100
message:
Teach CHKInventory with a parent_id_basename index how to load partial index contents.
modified:
bzrlib/inventory.py inventory.py-20050309040759-6648b84ca2005b37
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py 2008-11-14 02:19:53 +0000
+++ b/bzrlib/inventory.py 2008-11-14 03:36:34 +0000
@@ -1683,17 +1683,36 @@
def children(self):
"""Access the list of children of this inventory.
- Currently causes a full-load of all the children; a more sophisticated
- proxy object is planned.
+ With a parent_id_basename_to_file_id index, loads all the children,
+ without loads the entire index. Without is bad. A more sophisticated
+ proxy object might be nice, to allow partial loading of children as
+ well when specific names are accessed. (So path traversal can be
+ written in the obvious way but not examine siblings.).
"""
if self._children is not None:
return self._children
+ if self._chk_inventory.parent_id_basename_to_file_id is None:
+ # Slow path - read the entire inventory looking for kids.
+ result = {}
+ for file_id, bytes in self._chk_inventory.id_to_entry.iteritems():
+ entry = self._chk_inventory._bytes_to_entry(bytes)
+ if entry.parent_id == self.file_id:
+ result[entry.name] = entry
+ self._children = result
+ return result
result = {}
+ # XXX: Todo - use proxy objects for the children rather than loading
+ # all when the attribute is referenced.
+ parent_id_index = self._chk_inventory.parent_id_basename_to_file_id
+ child_ids = set()
+ for (parent_id, name_utf8), file_id in parent_id_index.iteritems(
+ key_filter=[(self.file_id,)]):
+ child_ids.add((file_id,))
# populate; todo: do by name
- for file_id, bytes in self._chk_inventory.id_to_entry.iteritems():
+ id_to_entry = self._chk_inventory.id_to_entry
+ for file_id, bytes in id_to_entry.iteritems(child_ids):
entry = self._chk_inventory._bytes_to_entry(bytes)
- if entry.parent_id == self.file_id:
- result[entry.name] = entry
+ result[entry.name] = entry
self._children = result
return result
More information about the bazaar-commits
mailing list