First select <number-of-database-connections> rows, then acquire up to one lock.

This seems to solve a concurrency issue where every so often the database
will acquire a lock on thousands of row because the limit is applied only
afterwards.
Fixed issue where the same item could be worked twice.