Rev 112: Use a cursor.lastrowid rather than executemany followed by a SELECT. in http://bazaar.launchpad.net/~bzr/bzr-history-db/trunk
John Arbash Meinel
john at arbash-meinel.com
Tue Apr 27 22:53:41 BST 2010
At http://bazaar.launchpad.net/~bzr/bzr-history-db/trunk
------------------------------------------------------------
revno: 112
revision-id: john at arbash-meinel.com-20100427215258-gna8751he7m9vc2h
parent: john at arbash-meinel.com-20100427212204-gzktjcesj9u9eakp
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk
timestamp: Tue 2010-04-27 16:52:58 -0500
message:
Use a cursor.lastrowid rather than executemany followed by a SELECT.
gets us to around 4.6s. Not quite as fast as just doing the INSERT but we had code
that assumed you didn't need the graph object most of the time.
-------------- next part --------------
=== modified file 'schema.py'
--- a/schema.py 2010-04-27 21:22:04 +0000
+++ b/schema.py 2010-04-27 21:52:58 +0000
@@ -208,20 +208,18 @@
missing = find_existing()
if missing:
ghosts = set()
- def get_gdfo(rev_id):
- node = graph._nodes[(rev_id,)]
- if node.gdfo == 1:
- # First rev, see if this is actually a ghost
- if node.parent_keys is None:
+ def insert_new():
+ for rev_id in missing:
+ node = graph._nodes[(rev_id,)]
+ if node.gdfo == 1 and node.parent_keys is None:
+ # First rev, see if this is actually a ghost
ghosts.add(rev_id)
- return node.gdfo
- def insert_new():
- cursor.executemany('INSERT INTO revision (revision_id, gdfo)'
- ' VALUES (?, ?)',
- [(m, get_gdfo(m)) for m in missing])
+ cursor.execute('INSERT INTO revision (revision_id, gdfo)'
+ ' VALUES (?, ?)', (rev_id, node.gdfo))
+ db_id = cursor.lastrowid
+ rev_id_to_db_id[rev_id] = db_id
+ db_id_to_rev_id[db_id] = rev_id
insert_new()
- ensure_revisions(cursor, missing, rev_id_to_db_id,
- db_id_to_rev_id, graph=graph)
if ghosts:
# TODO: We could turn this into a "revision_id IN ()", instead...
cursor.executemany("INSERT INTO ghost (db_id)"
More information about the bazaar-commits
mailing list