Rev 2732: Use the new index.key_count API to reduce full index iteration. in http://people.ubuntu.com/~robertc/baz2.0/repository

Robert Collins robertc at robertcollins.net
Fri Aug 24 03:14:21 BST 2007


At http://people.ubuntu.com/~robertc/baz2.0/repository

------------------------------------------------------------
revno: 2732
revision-id: robertc at robertcollins.net-20070824021419-1s9r53y1q2o6fd58
parent: robertc at robertcollins.net-20070824013533-d2gx1702ipr8rct9
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Fri 2007-08-24 12:14:19 +1000
message:
  Use the new index.key_count API to reduce full index iteration.
modified:
  bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
=== modified file 'bzrlib/repofmt/pack_repo.py'
--- a/bzrlib/repofmt/pack_repo.py	2007-08-24 00:05:53 +0000
+++ b/bzrlib/repofmt/pack_repo.py	2007-08-24 02:14:19 +0000
@@ -74,7 +74,7 @@
         self.transport = None
 
     def get_revision_count(self):
-        return len(list(self.revision_index.iter_all_entries()))
+        return self.revision_index.key_count()
 
 
 class RepositoryPackCollection(object):
@@ -146,8 +146,7 @@
         if self.repo._revision_all_indices is None:
             # trigger creation of the all revision index.
             self.repo._revision_store.get_revision_file(self.repo.get_transaction())
-        total_revisions = len(list(self.repo._revision_all_indices.iter_all_entries()))
-        # key_count() would be much more efficient 
+        total_revisions = self.repo._revision_all_indices.key_count()
         total_packs = len(self._names)
         if self._max_pack_count(total_revisions) >= total_packs:
             return False
@@ -162,7 +161,7 @@
         for index, transport_and_name in self.repo._revision_pack_map.iteritems():
             if index is None:
                 continue
-            revision_count = len(list(index.iter_all_entries()))
+            revision_count = index.key_count()
             if revision_count == 0:
                 # revision less packs are not generated by normal operation,
                 # only by operations like sign-my-commits, and thus will not
@@ -248,7 +247,7 @@
         if 'fetch' in debug.debug_flags:
             mutter('%s: create_pack: revisions copied: %s%s %d items t+%6.3fs',
                 time.ctime(), self.repo._upload_transport.base, random_name,
-                len(list(revision_index.iter_all_entries())),
+                revision_index.key_count(),
                 time.time() - start_time)
         # select inventory keys
         inv_keys = revision_keys # currently the same keyspace
@@ -263,7 +262,7 @@
         if 'fetch' in debug.debug_flags:
             mutter('%s: create_pack: inventories copied: %s%s %d items t+%6.3fs',
                 time.ctime(), self.repo._upload_transport.base, random_name,
-                len(list(inv_index.iter_all_entries())),
+                inv_index.key_count(),
                 time.time() - start_time)
         # select text keys
         text_nodes = self._index_contents(text_index_map)
@@ -273,7 +272,7 @@
         if 'fetch' in debug.debug_flags:
             mutter('%s: create_pack: file texts copied: %s%s %d items t+%6.3fs',
                 time.ctime(), self.repo._upload_transport.base, random_name,
-                len(list(text_index.iter_all_entries())),
+                text_index.key_count(),
                 time.time() - start_time)
         # select signature keys
         signature_nodes = self._index_contents(signature_index_map)
@@ -282,7 +281,7 @@
         if 'fetch' in debug.debug_flags:
             mutter('%s: create_pack: revision signatures copied: %s%s %d items t+%6.3fs',
                 time.ctime(), self.repo._upload_transport.base, random_name,
-                len(list(signature_index.iter_all_entries())),
+                signature_index.key_count(),
                 time.time() - start_time)
         # finish the pack
         writer.end()
@@ -292,10 +291,10 @@
             pack_hash.update(bytes)
         new_name = pack_hash.hexdigest()
         # if nothing has been written, discard the new pack.
-        if 0 == sum((len(list(revision_index.iter_all_entries())),
-            len(list(inv_index.iter_all_entries())),
-            len(list(text_index.iter_all_entries())),
-            len(list(signature_index.iter_all_entries())),
+        if 0 == sum((revision_index.key_count(),
+            inv_index.key_count(),
+            text_index.key_count(),
+            signature_index.key_count(),
             )):
             self.repo._upload_transport.delete(random_name)
             return None
@@ -385,7 +384,7 @@
             if self.repo._revision_all_indices is None:
                 # trigger creation of the all revision index.
                 self.repo._revision_store.get_revision_file(self.repo.get_transaction())
-            total_revisions = len(list(self.repo._revision_all_indices.iter_all_entries()))
+            total_revisions = self.repo._revision_all_indices.key_count()
             # XXX: the following may want to be a class, to pack with a given
             # policy.
             mutter('Packing repository %s, which has %d pack files, '
@@ -397,7 +396,7 @@
             for index, transport_and_name in self.repo._revision_pack_map.iteritems():
                 if index is None:
                     continue
-                revision_count = len(list(index.iter_all_entries()))
+                revision_count = index.key_count()
                 pack_operations[-1][0] += revision_count
                 pack_operations[-1][1].append(transport_and_name)
             self._execute_pack_operations(pack_operations)
@@ -811,12 +810,11 @@
         return self.repo._signature_knit
 
     def data_inserted(self):
-        # XXX: Should we define __len__ for indices?
         if (getattr(self.repo, '_revision_write_index', None) and
-            len(list(self.repo._revision_write_index.iter_all_entries()))):
+            self.repo._revision_write_index.key_count()):
             return True
         if (getattr(self.repo, '_signature_write_index', None) and
-            len(list(self.repo._signature_write_index.iter_all_entries()))):
+            self.repo._signature_write_index.key_count()):
             return True
         return False
 
@@ -933,7 +931,7 @@
     def data_inserted(self):
         # XXX: Should we define __len__ for indices?
         if (getattr(self.repo, '_text_write_index', None) and
-            len(list(self.repo._text_write_index.iter_all_entries()))):
+            self.repo._text_write_index.key_count()):
             return True
 
     def _ensure_all_index(self):
@@ -1047,7 +1045,7 @@
     def data_inserted(self):
         # XXX: Should we define __len__ for indices?
         if (getattr(self.repo, '_inv_write_index', None) and
-            len(list(self.repo._inv_write_index.iter_all_entries()))):
+            self.repo._inv_write_index.key_count()):
             return True
 
     def _ensure_all_index(self):



More information about the bazaar-commits mailing list