Don't use rails case_sensitive false, it is very slow.

This commit is contained in:
Raphael Sofaer 2011-05-12 15:15:56 -07:00
parent a46ff394b1
commit 5f531f14f1
3 changed files with 17 additions and 6 deletions

View file

@ -20,7 +20,7 @@ class Person < ActiveRecord::Base
has_one :profile
delegate :last_name, :to => :profile
before_save :downcase_diaspora_handle
before_validation :downcase_diaspora_handle
def downcase_diaspora_handle
diaspora_handle.downcase!
end
@ -39,7 +39,7 @@ class Person < ActiveRecord::Base
before_validation :clean_url
validates_presence_of :url, :profile, :serialized_public_key
validates_uniqueness_of :diaspora_handle, :case_sensitive => false
validates_uniqueness_of :diaspora_handle
scope :searchable, joins(:profile).where(:profiles => {:searchable => true})
@ -230,7 +230,7 @@ class Person < ActiveRecord::Base
def remove_all_traces
Notification.joins(:notification_actors).where(:notification_actors => {:person_id => self.id}).all.each{ |n| n.destroy}
end
def fix_profile
Webfinger.new(self.diaspora_handle).fetch
self.reload

View file

@ -19,7 +19,7 @@ class User < ActiveRecord::Base
before_validation :set_current_language, :on => :create
validates_presence_of :username
validates_uniqueness_of :username, :case_sensitive => false
validates_uniqueness_of :username
validates_format_of :username, :with => /\A[A-Za-z0-9_]+\z/
validates_length_of :username, :maximum => 32
validates_inclusion_of :language, :in => AVAILABLE_LANGUAGE_CODES
@ -76,12 +76,13 @@ class User < ActiveRecord::Base
self.language = I18n.locale.to_s if self.language.blank?
end
def self.find_for_authentication(conditions={})
def self.find_for_database_authentication(conditions={})
conditions = conditions.dup
conditions[:username] = conditions[:username].downcase
if conditions[:username] =~ /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i # email regex
conditions[:email] = conditions.delete(:username)
end
super(conditions)
where(conditions).first
end
def can_add?(person)

View file

@ -0,0 +1,10 @@
require 'db/migrate/20110421120744_downcase_usernames'
class DowncaseUsernamesAgain < ActiveRecord::Migration
def self.up
DowncaseUsernames.up
end
def self.down
DowncaseUsernames.down
end
end