sunspot/sunspot — pull request #170 by thhermansen (2012-01-21 21:04:21+00:00)
Title: Nested batches

## What is added?

The ability to nest `Sunspot.batch` calls is added through `Sunspot::Batcher`. The batcher is basically a stack which has a depth corresponding to `Sunspot.batch` calls. Each nested batch call is flushed independently.

## Why?

I encountered some problems `Sunspot.batch` the other day. I had some code I ran within `Sunspot.batch`, which in turn (down into the class hierarchy) did another Sunspot.batch and batched-indexed some of it's records.

When doing this I got `NoMethodError: undefined method `attrs' for nil:NilClass` when batched documents where to be indexed (as the `@batch` was set to `nil` when inner batch ended).

## Anything else?

Yeah, one thing: Maybe it should be possible to instruct `Sunspot.batch` that whenever a nested `batch` is called it should simply ignore it, so that everything within the outer `Sunspot.batch` block is guaranteed to be done in one batch. Just a thought :-)