From 14ac75d10d69f10944946997a51742ffab0bdb1b Mon Sep 17 00:00:00 2001
From: Jessica Tallon <jessica@megworld.co.uk>
Date: Thu, 17 Jul 2014 14:58:24 +0100
Subject: [PATCH] Fix #894 - index User.username field
---
mediagoblin/db/migrations.py | 13 +++++++++++++
mediagoblin/db/models.py | 2 +-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/mediagoblin/db/migrations.py b/mediagoblin/db/migrations.py
index 8e0b509..e580e08 100644
a
|
b
|
def fix_privilege_user_association_table(db):
|
789 | 789 | privilege_user_assoc.c.core__privilege_id.alter(name="user") |
790 | 790 | |
791 | 791 | db.commit() |
| 792 | |
| 793 | @RegisterMigration(22, MIGRATIONS) |
| 794 | def add_index_username_field(db): |
| 795 | """ |
| 796 | This indexes the User.username field which is frequently queried |
| 797 | for example a user logging in. This solves the issue #894 |
| 798 | """ |
| 799 | metadata = MetaData(bind=db.bind) |
| 800 | user_table = inspect_table(metadata, "core__users") |
| 801 | |
| 802 | user_table.c.username.alter(index=True) |
| 803 | |
| 804 | db.commit() |
| 805 | No newline at end of file |
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
index e388bd5..643d5d4 100644
a
|
b
|
class User(Base, UserMixin):
|
57 | 57 | __tablename__ = "core__users" |
58 | 58 | |
59 | 59 | id = Column(Integer, primary_key=True) |
60 | | username = Column(Unicode, nullable=False, unique=True) |
| 60 | username = Column(Unicode, nullable=False, unique=True, index=True) |
61 | 61 | # Note: no db uniqueness constraint on email because it's not |
62 | 62 | # reliable (many email systems case insensitive despite against |
63 | 63 | # the RFC) and because it would be a mess to implement at this |