Skip to content

Commit

Permalink
Attempted fix for concurrency issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
norman committed Dec 21, 2011
1 parent 8e852be commit 34ca0b6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/friendly_id/history.rb
Expand Up @@ -75,8 +75,14 @@ def self.included(model_class)
def build_slug
return unless should_generate_new_friendly_id?
# Allow reversion back to a previously used slug
slugs.where(:slug => friendly_id).delete_all
slugs.build :slug => friendly_id
Slug.transaction do
select = slugs.where(:slug => friendly_id)
unless Slug.connection.adapter_name =~ /sqlite/i
Slug.connection.execute "#{select.to_sql} FOR UPDATE"
end
select.delete_all
slugs.build :slug => friendly_id
end
end

# Adds a finder that explictly uses slugs from the slug table.
Expand Down

0 comments on commit 34ca0b6

Please sign in to comment.