Ticket #894: issue_894.patch

File issue_894.patch, 1.7 KB (added by Jessica Tallon, 10 years ago)
  • mediagoblin/db/migrations.py

    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):  
    789789        privilege_user_assoc.c.core__privilege_id.alter(name="user")
    790790
    791791    db.commit()
     792
     793@RegisterMigration(22, MIGRATIONS)
     794def 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
  • mediagoblin/db/models.py

    diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
    index e388bd5..643d5d4 100644
    a b class User(Base, UserMixin):  
    5757    __tablename__ = "core__users"
    5858
    5959    id = Column(Integer, primary_key=True)
    60     username = Column(Unicode, nullable=False, unique=True)
     60    username = Column(Unicode, nullable=False, unique=True, index=True)
    6161    # Note: no db uniqueness constraint on email because it's not
    6262    # reliable (many email systems case insensitive despite against
    6363    # the RFC) and because it would be a mess to implement at this