From 461a0eee45c568668264d852e5467cbe5202bdfc Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Tue, 10 Mar 2015 16:32:59 -0700 Subject: [PATCH] Add indexes to revision table The commit and parent columns were not indexed, meaning that checking to see if a commit's parent needed to be synced incurred a full table scan. Add indexes so it's faster. Change-Id: I093f8265a655a1fe2b7ba1be792b87e6d701fec1 --- .../1cdd4e2e74c_add_revision_indexes.py | 23 +++++++++++++++++++ gertty/db.py | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 gertty/alembic/versions/1cdd4e2e74c_add_revision_indexes.py diff --git a/gertty/alembic/versions/1cdd4e2e74c_add_revision_indexes.py b/gertty/alembic/versions/1cdd4e2e74c_add_revision_indexes.py new file mode 100644 index 0000000..b517b8e --- /dev/null +++ b/gertty/alembic/versions/1cdd4e2e74c_add_revision_indexes.py @@ -0,0 +1,23 @@ +"""add revision indexes + +Revision ID: 1cdd4e2e74c +Revises: 4a802b741d2f +Create Date: 2015-03-10 16:17:41.330825 + +""" + +# revision identifiers, used by Alembic. +revision = '1cdd4e2e74c' +down_revision = '4a802b741d2f' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.create_index(op.f('ix_revision_commit'), 'revision', ['commit']) + op.create_index(op.f('ix_revision_parent'), 'revision', ['parent']) + + +def downgrade(): + pass diff --git a/gertty/db.py b/gertty/db.py index 7b88dbc..4948177 100644 --- a/gertty/db.py +++ b/gertty/db.py @@ -71,8 +71,8 @@ revision_table = Table( Column('change_key', Integer, ForeignKey("change.key"), index=True), Column('number', Integer, index=True, nullable=False), Column('message', Text, nullable=False), - Column('commit', String(255), nullable=False), - Column('parent', String(255), nullable=False), + Column('commit', String(255), index=True, nullable=False), + Column('parent', String(255), index=True, nullable=False), Column('fetch_auth', Boolean, nullable=False), Column('fetch_ref', String(255), nullable=False), Column('pending_message', Boolean, index=True, nullable=False),