Slightly More Efficient

A slightly more efficient implementation of the above change to form_spam_protection.
This commit is contained in:
Jacques Distler 2008-01-17 03:47:08 -06:00
parent 72b4f97382
commit e7d080db25

View file

@ -9,8 +9,10 @@ module ActionView
session[:form_keys] ||= {} session[:form_keys] ||= {}
form_key = Digest::SHA1.hexdigest(self.object_id.to_s + rand.to_s) form_key = Digest::SHA1.hexdigest(self.object_id.to_s + rand.to_s)
session[:form_keys][form_key] = [Time.now, 0] session[:form_keys][form_key] = [Time.now, 0]
first = session[:form_keys].values.sort { |a,b| a[0] <=> b[0] } [0] if session[:form_keys].length > 30
session[:form_keys].delete(session[:form_keys].index(first)) if session[:form_keys].length > 30 first = session[:form_keys].values.sort { |a,b| a[0] <=> b[0] } [0]
session[:form_keys].delete(session[:form_keys].index(first))
end
out << domEnkode(form_key) out << domEnkode(form_key)
end end
end end