Fix database concurrency issue

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.
Since this will basically just set the lock, I think it can be simplified down to just:
```sql
                 SELECT id FROM candidates
                 WHERE pg_try_advisory_xact_lock(id)
                 LIMIT 1
```

Or maybe there's something I'm missing...