Don't use rails case_sensitive false, it is very slow.
This commit is contained in:
parent
a46ff394b1
commit
5f531f14f1
3 changed files with 17 additions and 6 deletions
|
|
@ -20,7 +20,7 @@ class Person < ActiveRecord::Base
|
||||||
has_one :profile
|
has_one :profile
|
||||||
delegate :last_name, :to => :profile
|
delegate :last_name, :to => :profile
|
||||||
|
|
||||||
before_save :downcase_diaspora_handle
|
before_validation :downcase_diaspora_handle
|
||||||
def downcase_diaspora_handle
|
def downcase_diaspora_handle
|
||||||
diaspora_handle.downcase!
|
diaspora_handle.downcase!
|
||||||
end
|
end
|
||||||
|
|
@ -39,7 +39,7 @@ class Person < ActiveRecord::Base
|
||||||
before_validation :clean_url
|
before_validation :clean_url
|
||||||
|
|
||||||
validates_presence_of :url, :profile, :serialized_public_key
|
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})
|
scope :searchable, joins(:profile).where(:profiles => {:searchable => true})
|
||||||
|
|
||||||
|
|
@ -230,7 +230,7 @@ class Person < ActiveRecord::Base
|
||||||
def remove_all_traces
|
def remove_all_traces
|
||||||
Notification.joins(:notification_actors).where(:notification_actors => {:person_id => self.id}).all.each{ |n| n.destroy}
|
Notification.joins(:notification_actors).where(:notification_actors => {:person_id => self.id}).all.each{ |n| n.destroy}
|
||||||
end
|
end
|
||||||
|
|
||||||
def fix_profile
|
def fix_profile
|
||||||
Webfinger.new(self.diaspora_handle).fetch
|
Webfinger.new(self.diaspora_handle).fetch
|
||||||
self.reload
|
self.reload
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class User < ActiveRecord::Base
|
||||||
before_validation :set_current_language, :on => :create
|
before_validation :set_current_language, :on => :create
|
||||||
|
|
||||||
validates_presence_of :username
|
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_format_of :username, :with => /\A[A-Za-z0-9_]+\z/
|
||||||
validates_length_of :username, :maximum => 32
|
validates_length_of :username, :maximum => 32
|
||||||
validates_inclusion_of :language, :in => AVAILABLE_LANGUAGE_CODES
|
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?
|
self.language = I18n.locale.to_s if self.language.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_for_authentication(conditions={})
|
def self.find_for_database_authentication(conditions={})
|
||||||
|
conditions = conditions.dup
|
||||||
conditions[:username] = conditions[:username].downcase
|
conditions[:username] = conditions[:username].downcase
|
||||||
if conditions[:username] =~ /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i # email regex
|
if conditions[:username] =~ /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i # email regex
|
||||||
conditions[:email] = conditions.delete(:username)
|
conditions[:email] = conditions.delete(:username)
|
||||||
end
|
end
|
||||||
super(conditions)
|
where(conditions).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_add?(person)
|
def can_add?(person)
|
||||||
|
|
|
||||||
10
db/migrate/20110512220310_downcase_usernames_again.rb
Normal file
10
db/migrate/20110512220310_downcase_usernames_again.rb
Normal 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
|
||||||
Loading…
Reference in a new issue