(#1926) - More efficient changes() for idb/websql

This moves more of the limit/doc_ids filtering logic
up-front, so that we don't have to read the entire
changes stream into memory and then filter at the end.

This also fixes an error with 'rev' in websql when
the docid contains the '\u0000' character.