Rev 3054: Tests that buffer_all does load all child indices, and but only if they need it. in http://bzr.arbash-meinel.com/branches/bzr/0.93-dev/index_buffer_all
John Arbash Meinel
john at arbash-meinel.com
Fri Nov 30 02:16:47 GMT 2007
At http://bzr.arbash-meinel.com/branches/bzr/0.93-dev/index_buffer_all
------------------------------------------------------------
revno: 3054
revision-id:john at arbash-meinel.com-20071130021614-hdymy9xgr32v0uee
parent: john at arbash-meinel.com-20071129232902-xlmhssl1u4lyct64
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: index_buffer_all
timestamp: Thu 2007-11-29 20:16:14 -0600
message:
Tests that buffer_all does load all child indices, and but only if they need it.
modified:
bzrlib/index.py index.py-20070712131115-lolkarso50vjr64s-1
bzrlib/tests/test_index.py test_index.py-20070712131115-lolkarso50vjr64s-2
-------------- next part --------------
=== modified file 'bzrlib/index.py'
--- a/bzrlib/index.py 2007-11-29 23:29:02 +0000
+++ b/bzrlib/index.py 2007-11-30 02:16:14 +0000
@@ -1115,6 +1115,19 @@
index.validate()
def buffer_all(self):
+ """Pre-load all of the indexes.
+
+ This goes to every child index, and tells it to buffer all of its data
+ if it has not yet done so. Functions that need to call this should be
+ reworked to use an algorithm that does not require the whole history.
+ However, until they are fixed, this can be used to improve performance
+ for O(History) algorithms.
+ """
+ if 'evil' in debug.debug_flags:
+ # Do we want to use 4 here, since it is really the caller of the
+ # algorithm that needs buffer_all?
+ trace.mutter_callsite(3,
+ "buffer_all scales with size of history.")
for index in self._indices:
if index._nodes is None:
index._buffer_all()
=== modified file 'bzrlib/tests/test_index.py'
--- a/bzrlib/tests/test_index.py 2007-10-15 07:56:04 +0000
+++ b/bzrlib/tests/test_index.py 2007-11-30 02:16:14 +0000
@@ -825,6 +825,33 @@
index.insert_index(0, index1)
self.assertEqual([(index1, ('key', ), '')], list(index.iter_all_entries()))
+ def test_buffer_all(self):
+ log = []
+ def make_buffer_all(idx, name):
+ _buffer = idx._buffer_all
+ def _buffer_all():
+ log.append(name)
+ _buffer()
+ idx._buffer_all = _buffer_all
+
+ index1 = self.make_index('name1', nodes=[(('name', ), 'data', ())])
+ make_buffer_all(index1, 'index1')
+ index2 = self.make_index('name2', nodes=[(('2', ), '', ())])
+ make_buffer_all(index2, 'index2')
+ index = CombinedGraphIndex([index1, index2])
+ for idx in index._indices:
+ self.assertIs(None, idx._nodes)
+ self.assertEqual([], log)
+ index.buffer_all()
+ for idx in index._indices:
+ self.assertIsNot(None, idx._nodes)
+ self.assertEqual(['index1', 'index2'], log)
+ index.buffer_all() # All are already buffered
+ self.assertEqual(['index1', 'index2'], log)
+ index2._nodes = None
+ index.buffer_all()
+ self.assertEqual(['index1', 'index2', 'index2'], log)
+
def test_iter_all_entries_empty(self):
index = CombinedGraphIndex([])
self.assertEqual([], list(index.iter_all_entries()))
More information about the bazaar-commits
mailing list