diff options
author | Jessica Tallon <jessica@megworld.co.uk> | 2014-07-17 14:58:24 +0100 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2014-07-17 10:21:29 -0500 |
commit | 892eed590fb30131ea2e8612da5ba22fa24f690c (patch) | |
tree | 5039d4678b0529689a4b802a275467f2b5b2dabf /mediagoblin/db/migrations.py | |
parent | ffbf9c8b438ef8d203da54807b6ff5db3cc4d334 (diff) | |
download | mediagoblin-892eed590fb30131ea2e8612da5ba22fa24f690c.tar.lz mediagoblin-892eed590fb30131ea2e8612da5ba22fa24f690c.tar.xz mediagoblin-892eed590fb30131ea2e8612da5ba22fa24f690c.zip |
Fix #894 - index User.username field
This commit sponsored by Emily O'Leary. Thank you!
Diffstat (limited to 'mediagoblin/db/migrations.py')
-rw-r--r-- | mediagoblin/db/migrations.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py index 8e0b5096..59aec4d2 100644 --- a/mediagoblin/db/migrations.py +++ b/mediagoblin/db/migrations.py @@ -19,7 +19,7 @@ import uuid from sqlalchemy import (MetaData, Table, Column, Boolean, SmallInteger, Integer, Unicode, UnicodeText, DateTime, - ForeignKey, Date) + ForeignKey, Date, Index) from sqlalchemy.exc import ProgrammingError from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.sql import and_ @@ -789,3 +789,17 @@ def fix_privilege_user_association_table(db): privilege_user_assoc.c.core__privilege_id.alter(name="user") db.commit() + +@RegisterMigration(22, MIGRATIONS) +def add_index_username_field(db): + """ + This indexes the User.username field which is frequently queried + for example a user logging in. This solves the issue #894 + """ + metadata = MetaData(bind=db.bind) + user_table = inspect_table(metadata, "core__users") + + new_index = Index("ix_core__users_uploader", user_table.c.username) + new_index.create() + + db.commit() |