DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Speeding Up Your Acts_as_tokenized Inserts

  • submit to reddit
        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)
-      token = Digest::MD5.hexdigest("#{inspect}#{}").first(size)
+      token = Digest::MD5.hexdigest("#{inspect}#{}#{rand}").first(size)
     end while ! if block_given?