Logic is wrong here:

- limit isn't correctly applied (you could reach zero limit when ids has fewer than limit items)
- sqlLimit isn't used any more.