Rev 32: Create an api for inserting many dotted_revno entries at a time. in http://bzr.arbash-meinel.com/plugins/history_db

John Arbash Meinel john at arbash-meinel.com
Sun Apr 4 17:53:11 BST 2010


At http://bzr.arbash-meinel.com/plugins/history_db

------------------------------------------------------------
revno: 32
revision-id: john at arbash-meinel.com-20100404165308-qzj0az9u5x5qoi6u
parent: john at arbash-meinel.com-20100404153249-lqy4j3f4dcxwzfll
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: history_db
timestamp: Sun 2010-04-04 11:53:08 -0500
message:
  Create an api for inserting many dotted_revno entries at a time.
  
  Doesn't seem to affect runtime performance. Probably just not a bottleneck.
-------------- next part --------------
=== modified file 'history_db.py'
--- a/history_db.py	2010-04-04 15:32:49 +0000
+++ b/history_db.py	2010-04-04 16:53:08 +0000
@@ -79,13 +79,16 @@
             return False
         self._stats['total_nodes_inserted'] += len(nodes)
         tip_db_id = self._rev_id_to_db_id[tip_rev_id]
+        revno_entries = []
         for node in nodes:
-            schema.create_dotted_revno(self._cursor,
-                tip_revision=tip_db_id,
-                merged_revision=self._rev_id_to_db_id[node.key[0]],
-                revno='.'.join(map(str, node.revno)),
-                end_of_merge=node.end_of_merge,
-                merge_depth=node.merge_depth)
+            # TODO: Do we need to track the 'end_of_merge' and 'merge_depth'
+            #       fields?
+            revno_entries.append((tip_db_id,
+                                  self._rev_id_to_db_id[node.key[0]],
+                                  '.'.join(map(str, node.revno)),
+                                  node.end_of_merge,
+                                  node.merge_depth))
+        schema.create_dotted_revnos(self._cursor, revno_entries)
         return True
 
     def _update_parents(self, nodes):

=== modified file 'schema.py'
--- a/schema.py	2010-04-02 22:17:01 +0000
+++ b/schema.py	2010-04-04 16:53:08 +0000
@@ -218,3 +218,26 @@
         '                          revno, end_of_merge, merge_depth)'
         ' VALUES (?, ?, ?, ?, ?)',
         (tip_revision, merged_revision, revno, end_of_merge, merge_depth))
+
+
+def create_dotted_revnos(cursor, revno_entries):
+    """Create a dotted revno entry for this info."""
+    # # TODO: Consider changing this to a bulk SELECT a bunch which may be
+    # #       missing, .executemany() the ones that aren't present
+    # existing = cursor.execute('SELECT revno, end_of_merge, merge_depth'
+    #                           '  FROM dotted_revno'
+    #                           ' WHERE tip_revision = ?'
+    #                           '   AND merged_revision = ?',
+    #                           (tip_revision, merged_revision)).fetchone()
+    # if existing is not None:
+    #     new_value = (revno, end_of_merge, merge_depth)
+    #     if existing != new_value:
+    #         raise ValueError('Disagreement in the graph. Wanted to add'
+    #             ' node %s, but %s already exists'
+    #             % (new_value, existing))
+    #     return
+    cursor.executemany(
+        'INSERT INTO dotted_revno (tip_revision, merged_revision,'
+        '                          revno, end_of_merge, merge_depth)'
+        ' VALUES (?, ?, ?, ?, ?)',
+        revno_entries)



More information about the bazaar-commits mailing list