gpt4 book ai didi

ruby-on-rails - Ruby on rails authlogic 配置(摆脱大写检查)

转载 作者:数据小太阳 更新时间:2023-10-29 07:54:29 25 4
gpt4 key购买 nike

authlogic rails gem 在 sql 查询中执行 LOWER。

SELECT * FROM `users` WHERE (LOWER(`users`.email) = 'test@example.com') LIMIT 1

我想去掉 LOWER 部分,因为它似乎大大减慢了查询速度。我宁愿在代码中减少大小写,因为这个查询似乎很昂贵。

我不确定在 authlogic 中的何处更改此行为。

谢谢!

最佳答案

此注释来自 find_by_smart_case_login_field 方法上方的 lib/authlogic/acts_as_authentic/login.rb:

    # This method allows you to find a record with the given login. If you notice, with ActiveRecord you have the
# validates_uniqueness_of validation function. They give you a :case_sensitive option. I handle this in the same
# manner that they handle that. If you are using the login field and set false for the :case_sensitive option in
# validates_uniqueness_of_login_field_options this method will modify the query to look something like:
#
# first(:conditions => ["LOWER(#{quoted_table_name}.#{login_field}) = ?", login.downcase])
#
# If you don't specify this it calls the good old find_by_* method:
#
# find_by_login(login)
#
# The above also applies for using email as your login, except that you need to set the :case_sensitive in
# validates_uniqueness_of_email_field_options to false.
#
# The only reason I need to do the above is for Postgres and SQLite since they perform case sensitive searches with the
# find_by_* methods.

您是否在电子邮件验证中设置了 case_sensitive = false?如果是这样,将其移除应该可以解决此问题,而无需修补任何代码。

关于ruby-on-rails - Ruby on rails authlogic 配置(摆脱大写检查),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2879725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com