Avoid unnecessary, potentially huge db query on index update

This is a port of #433 to master with additional improvements suggested by @acdha.

`pks_seen` is only needed if objects are removed from the index, so only compute it if necessary. `pks_seen` will also not build an intermediary list in this patch.

I don't know the consequences of removing `smart_str`, so I kept it in.

This fix becomes relevant when updating huge indexes, as the indexing processes will not start before all primary keys of all index objects are retrieved and this takes a lot of time and memory.