{"issue":{"state":"closed","created_at":"2010-12-17T21:08:45Z","updated_at":"2011-12-01T22:20:58Z","comments":9,"user":{"gravatar_id":"625cb1796316a98d3bbe205a040035c3","id":6457,"url":"https://api.github.com/users/tylerhunt","avatar_url":"https://secure.gravatar.com/avatar/625cb1796316a98d3bbe205a040035c3?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"tylerhunt"},"body":"As discussed on the recent mailing list [thread][], this change makes use of Rails 3's `after_rollback` hook to have the model automatically removed from the index when a rollback occurs. This bit me recently when I was running a Rake task wrapped in a transaction that was syncing hundreds of records, but would rollback if there was a failure of any sort. I ended up with lots of orphaned records in Solr, which wouldn't have happened had this callback been in place.\r\n\r\nI also took the liberty of fixing some deprecation in the Rails 3 app, and removing some extraneous whitespace throughout the library and spec suite.\r\n\r\n[thread]: http://groups.google.com/group/ruby-sunspot/browse_thread/thread/6706b9a4f6ac4cdb","assignee":null,"id":480833,"labels":[{"name":"feature","color":"02e10c","url":"https://api.github.com/repos/sunspot/sunspot/labels/feature"}],"pull_request":{"patch_url":"https://github.com/sunspot/sunspot/pull/19.patch","html_url":"https://github.com/sunspot/sunspot/pull/19","diff_url":"https://github.com/sunspot/sunspot/pull/19.diff"},"number":19,"title":"Added Support for Automatic Removal After Rollback","html_url":"https://github.com/sunspot/sunspot/issues/19","closed_at":"2011-12-01T19:48:04Z","url":"https://api.github.com/repos/sunspot/sunspot/issues/19","milestone":null},"action":"created","comment":{"created_at":"2011-12-01T22:20:58Z","updated_at":"2011-12-01T22:20:58Z","user":{"gravatar_id":"f81560e8e8743d0df6a467b88df31bbc","id":521248,"url":"https://api.github.com/users/iwiznia","avatar_url":"https://secure.gravatar.com/avatar/f81560e8e8743d0df6a467b88df31bbc?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","login":"iwiznia"},"body":"I think the after_commit is ok for rails 3.M aybe for rails 2 support we can use this gem:\r\nhttps://github.com/freelancing-god/after_commit\r\nmentioned here:\r\nhttp://stackoverflow.com/questions/2220788/rails-after-commit\r\nI really avoided this issue by using delayed_job to run the indexation in a sepparate process, since the indexing happens some seconds after, and it reloads the object, the problem dissapears. That's of course if you can allow the few seconds delay of the solr index.","id":2983064,"url":"https://api.github.com/repos/sunspot/sunspot/issues/comments/2983064"}}