Lower the time spent scanning lastseen DB.

The total DB access time will thus not depend on the time spent running the callback (it seems to be huge in the case of reverse DNS resolution).

This commit makes it easier to later convert the scan into an RDONLY operation.

(cherry picked from commit bec9cd1d2142dda7836b1eebb982e7297dafebf1)