Skip to content

Commit

Permalink
Faster uniqueness queries, closes heartcombo#917
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Mar 15, 2011
1 parent cb778d0 commit 74166e2
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
@@ -1,5 +1,6 @@
* bug fix
* Properly ignore path prefix on omniauthable
* Faster uniqueness queries

== 1.2.rc2

Expand Down
4 changes: 2 additions & 2 deletions lib/devise.rb
Expand Up @@ -70,9 +70,9 @@ module Strategies
@@request_keys = []

# Keys that should be case-insensitive.
# Empty by default for backwards compatibility.
# False by default for backwards compatibility.
mattr_accessor :case_insensitive_keys
@@case_insensitive_keys = []
@@case_insensitive_keys = false

# If http authentication is enabled by default.
mattr_accessor :http_authenticatable
Expand Down
4 changes: 2 additions & 2 deletions lib/devise/models/authenticatable.rb
Expand Up @@ -101,7 +101,7 @@ def http_authenticatable?(strategy)
#
def find_for_authentication(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)
end

Expand All @@ -112,7 +112,7 @@ def find_or_initialize_with_error_by(attribute, value, error=:invalid) #:nodoc:

# 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:
case_insensitive_keys.each { |k| attributes[k].try(:downcase!) }
(case_insensitive_keys || []).each { |k| attributes[k].try(:downcase!) }

attributes = attributes.slice(*required_attributes)
attributes.delete_if { |key, value| value.blank? }
Expand Down
2 changes: 1 addition & 1 deletion lib/devise/models/database_authenticatable.rb
Expand Up @@ -78,7 +78,7 @@ def authenticatable_salt

# Downcase case-insensitive 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

# Digests the password using bcrypt.
Expand Down
2 changes: 1 addition & 1 deletion lib/devise/models/validatable.rb
Expand Up @@ -24,7 +24,7 @@ def self.included(base)
base.class_eval do
validates_presence_of :email, :if => :email_required?
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

with_options :if => :password_required? do |v|
Expand Down

0 comments on commit 74166e2

Please sign in to comment.