<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -199,12 +199,10 @@ module Randomba
       # Generate the text for the friendly id, ensuring no duplication.
       def generate_friendly_id
         slug_text = truncated_friendly_id_base
-        count = Slug.count_matches(slug_text, self.class.to_s, :all,
-        :conditions =&gt; &quot;sluggable_id &lt;&gt; #{self.id or 0}&quot;)
-        if count == 0
+        if !Slug.find_by_name(slug_text)
           return slug_text
         else
-          generate_friendly_id_with_extension(slug_text, count)
+          generate_friendly_id_with_extension(slug_text)
         end
       end
 
@@ -256,20 +254,16 @@ module Randomba
       # extension is added.
       NUM_CHARS_RESERVED_FOR_EXTENSION = 5
 
-      def generate_friendly_id_with_extension(slug_text, count)
-        extension = &quot;-&quot; + (count + 1).to_s
-        if extension.length &gt; NUM_CHARS_RESERVED_FOR_EXTENSION
-          raise FriendlyId::SlugGenerationError.new(&quot;slug text #{slug_text} &quot; +
-            &quot;goes over limit for similarly named slugs&quot;)
-        end
+      def generate_friendly_id_with_extension(slug_text)
+        start = 0
+        extension = &quot;-&quot; + (start + 1).to_s
         slug_text = truncated_friendly_id_base + extension
-        count = Slug.count_matches(slug_text, self.class.to_s, :all,
-          :conditions =&gt; &quot;sluggable_id &lt;&gt; #{self.id or 0}&quot;)
-        if count != 0
-          slug_text = truncated_friendly_id_base + &quot;-&quot; + (count + 1).to_s
-        else
-          return slug_text
+        while Slug.find_by_name(slug_text)
+          start = start + 1
+          extension = &quot;-&quot; + (start + 1).to_s
+          slug_text = truncated_friendly_id_base + extension
         end
+        return slug_text
       end
     end
 </diff>
      <filename>lib/friendly_id.rb</filename>
    </modified>
    <modified>
      <diff>@@ -14,7 +14,7 @@ namespace :friendly_id do
     	records.each do |r|
       	   r.set_slug
            r.save!
-           puts &quot;#{sluggable_class.to_s}(#{r.id}) friendly_id set to \&quot;#{r.slug.name}\&quot;&quot;
+           puts &quot;#{sluggable_class.to_s}(#{r.id}) friendly_id set to \&quot;#{r.slug.name}\&quot;&quot;  
 	end
       end
     end</diff>
      <filename>tasks/friendly_id_tasks.rake</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>afbb161ac5de41a2079ba53c9555049e37118e7e</id>
    </parent>
  </parents>
  <author>
    <name>Tim Kadom</name>
    <email>tkadom@skiptree.com</email>
  </author>
  <url>http://github.com/tkadom/friendly_id/commit/0cfcde309b96bc718db204837a46098c8fcbec60</url>
  <id>0cfcde309b96bc718db204837a46098c8fcbec60</id>
  <committed-date>2008-10-29T08:24:58-07:00</committed-date>
  <authored-date>2008-10-29T08:24:58-07:00</authored-date>
  <message>friendly id was using the record count to determine the next id for a generated slug.  This algorithm does not take into account hat aged records might have been removed with the associated rake task.  i.e. if we created three slugs from the same base text and had base-val-1, base-val-2, and base-val-3 as our slugs initially.  We then run a removal of aged slugs, leaving only base-val-2, and base-val-3, we would generate a count of 2 slugs which share the same slug root.  the count would then try to create a base-val-3 slug which would error out on uniqueness validation.  I changed the algorithm so that it is not as efficient, but it will actually re-use values that have been deleted by iterating through the mathing base slugs until an open slot is found for the new slug.</message>
  <tree>7a755ac0f2ab4550baa98605769bc6aab2ca6d84</tree>
  <committer>
    <name>Tim Kadom</name>
    <email>tkadom@skiptree.com</email>
  </committer>
</commit>
