Add indexes to speed up jobs on the queue
Small refactor to do query in db