mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Faster uniqueness queries, closes #917
This commit is contained in:
parent
cb778d033f
commit
74166e224b
5 changed files with 7 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
* bug fix
|
* bug fix
|
||||||
* Properly ignore path prefix on omniauthable
|
* Properly ignore path prefix on omniauthable
|
||||||
|
* Faster uniqueness queries
|
||||||
|
|
||||||
== 1.2.rc2
|
== 1.2.rc2
|
||||||
|
|
||||||
|
|
|
@ -70,9 +70,9 @@ module Devise
|
||||||
@@request_keys = []
|
@@request_keys = []
|
||||||
|
|
||||||
# Keys that should be case-insensitive.
|
# Keys that should be case-insensitive.
|
||||||
# Empty by default for backwards compatibility.
|
# False by default for backwards compatibility.
|
||||||
mattr_accessor :case_insensitive_keys
|
mattr_accessor :case_insensitive_keys
|
||||||
@@case_insensitive_keys = []
|
@@case_insensitive_keys = false
|
||||||
|
|
||||||
# If http authentication is enabled by default.
|
# If http authentication is enabled by default.
|
||||||
mattr_accessor :http_authenticatable
|
mattr_accessor :http_authenticatable
|
||||||
|
|
|
@ -101,7 +101,7 @@ module Devise
|
||||||
#
|
#
|
||||||
def find_for_authentication(conditions)
|
def find_for_authentication(conditions)
|
||||||
filter_auth_params(conditions)
|
filter_auth_params(conditions)
|
||||||
case_insensitive_keys.each { |k| conditions[k].try(:downcase!) }
|
(case_insensitive_keys || []).each { |k| conditions[k].try(:downcase!) }
|
||||||
to_adapter.find_first(conditions)
|
to_adapter.find_first(conditions)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ module Devise
|
||||||
|
|
||||||
# Find an initialize a group of attributes based on a list of required attributes.
|
# Find an initialize a group of attributes based on a list of required attributes.
|
||||||
def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc:
|
def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc:
|
||||||
case_insensitive_keys.each { |k| attributes[k].try(:downcase!) }
|
(case_insensitive_keys || []).each { |k| attributes[k].try(:downcase!) }
|
||||||
|
|
||||||
attributes = attributes.slice(*required_attributes)
|
attributes = attributes.slice(*required_attributes)
|
||||||
attributes.delete_if { |key, value| value.blank? }
|
attributes.delete_if { |key, value| value.blank? }
|
||||||
|
|
|
@ -78,7 +78,7 @@ module Devise
|
||||||
|
|
||||||
# Downcase case-insensitive keys
|
# Downcase case-insensitive keys
|
||||||
def downcase_keys
|
def downcase_keys
|
||||||
self.class.case_insensitive_keys.each { |k| self[k].try(:downcase!) }
|
(self.class.case_insensitive_keys || []).each { |k| self[k].try(:downcase!) }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Digests the password using bcrypt.
|
# Digests the password using bcrypt.
|
||||||
|
|
|
@ -24,7 +24,7 @@ module Devise
|
||||||
base.class_eval do
|
base.class_eval do
|
||||||
validates_presence_of :email, :if => :email_required?
|
validates_presence_of :email, :if => :email_required?
|
||||||
validates_uniqueness_of :email, :scope => authentication_keys[1..-1],
|
validates_uniqueness_of :email, :scope => authentication_keys[1..-1],
|
||||||
:case_sensitive => case_insensitive_keys.exclude?(:email), :allow_blank => true
|
:case_sensitive => (case_insensitive_keys != false), :allow_blank => true
|
||||||
validates_format_of :email, :with => email_regexp, :allow_blank => true
|
validates_format_of :email, :with => email_regexp, :allow_blank => true
|
||||||
|
|
||||||
with_options :if => :password_required? do |v|
|
with_options :if => :password_required? do |v|
|
||||||
|
|
Loading…
Reference in a new issue