toastdriven/django-haystack — pull request #974 by vikalpj (2014-03-17 18:59:40+00:00)
Title: fix update index with remove option

While removing objects it doesn't remove all stale objects. This was because of the slice that we were creating from starting
```
for start in range(0, total, batch_size):
upper_bound = start + batch_size
```

which causes slice in do remove function to skip some objects here
```
def do_remove(backend, index, model, pks_seen, start, upper_bound, verbosity=1):
# Fetch a list of results.
# Can't do pk range, because id's are strings (thanks comments
# & UUIDs!).
stuff_in_the_index = SearchQuerySet(using=backend.connection_alias).models(model)[start:upper_bound]

# Iterate over those results.
for result in stuff_in_the_index:
# Be careful not to hit the DB.
if not smart_bytes(result.pk) in pks_seen:
# The id is NOT in the small_cache_qs, issue a delete.
if verbosity >= 2:
print(" removing %s." % result.pk)

backend.remove(".".join([result.app_label, result.model_name, str(result.pk)]))
```
as this function is removing objects for as well for particular slices so update command is not able to remove all the stale objects.