improve task archiver query performance

fixes #4865