public
Rubygem
Description: FriendlyId is the “Swiss Army bulldozer” of slugging and permalink plugins for ActiveRecord. It allows you to create pretty URL’s and work with human-friendly strings as if they were numeric ids for ActiveRecord models.
Homepage: http://friendly-id.rubyforge.org
Clone URL: git://github.com/norman/friendly_id.git
Made friendly_id::make_slugs update records in chunks of 1000 to avoid running
out of memory with large datasets. Thanks to Tim Kadom for this update
(resolves ticket #6).
norman (author)
Fri Oct 31 07:56:14 -0700 2008
commit  61ab15579986f9240f3d74a6f8affcaa13ebfa77
tree    51aaac1cb54657262ee98923bb34cc5a81597037
parent  64f7bf2d7d0601c876c6798f03b1c4ffef9fbb7a
...
5
6
7
8
9
10
11
12
 
 
 
 
 
 
 
13
14
15
...
5
6
7
 
 
 
 
 
8
9
10
11
12
13
14
15
16
17
0
@@ -5,11 +5,13 @@ namespace :friendly_id do
0
     if !sluggable_class.friendly_id_options[:use_slug]
0
       raise "Class \"#{sluggable_class.to_s}\" doesn't appear to be using slugs"
0
     end
0
-    records = sluggable_class.find(:all, :include => :slugs, :conditions => "slugs.id IS NULL")
0
-    records.each do |r|
0
-      r.set_slug
0
-      r.save!
0
-      puts "#{sluggable_class.to_s}(#{r.id}) friendly_id set to \"#{r.slug.name}\""
0
+    while records = sluggable_class.find(:all, :include => :slugs, :conditions => "slugs.id IS NULL", :limit => 1000) do
0
+      break if records.size == 0
0
+      records.each do |r|
0
+        r.set_slug
0
+        r.save!
0
+        puts "#{sluggable_class.to_s}(#{r.id}) friendly_id set to \"#{r.slug.name}\""  
0
+      end
0
     end
0
   end
0
 

Comments