Over a million developers have joined DZone.

Speeding Up Your Acts_as_tokenized Inserts

·
You might want to apply this diff to your token_generator plugin. Otherwise for saving identical models the minimum time taken is one per second. Not fun!



Index: vendor/plugins/token_generator/lib/token_generator.rb
===================================================================
--- vendor/plugins/token_generator/lib/token_generator.rb       (revision 1233)
+++ vendor/plugins/token_generator/lib/token_generator.rb       (working copy)
@@ -1,7 +1,7 @@
 module TokenGenerator
   def generate_token(size = 12, &validity)
     begin
-      token = Digest::MD5.hexdigest("#{inspect}#{Time.now}").first(size)
+      token = Digest::MD5.hexdigest("#{inspect}#{Time.now}#{rand}").first(size)
     end while !validity.call(token) if block_given?
     
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}