potential fix for #3189

This commit is contained in:
r888888888
2017-08-24 15:39:06 -07:00
parent d124ff8128
commit 18f617e08a

View File

@@ -138,8 +138,13 @@ class User < ApplicationRecord
module ClassMethods
def name_to_id(name)
Cache.get("uni:#{Cache.sanitize(name)}", 4.hours) do
select_value_sql("SELECT id FROM users WHERE lower(name) = ?", name.mb_chars.downcase.tr(" ", "_").to_s)
Cache.get("uni:#{Cache.hash(name)}", 4.hours) do
val = select_value_sql("SELECT id FROM users WHERE lower(name) = ?", name.mb_chars.downcase.tr(" ", "_").to_s)
if val.present?
val.to_i
else
nil
end
end
end
@@ -168,7 +173,7 @@ class User < ApplicationRecord
def update_cache
Cache.put("uin:#{id}", name)
Cache.put("uni:#{Cache.sanitize(name)}", id)
Cache.put("uni:#{Cache.hash(name)}", id)
end
def update_remote_cache