changed applyToDatabaseNames to use batching

Inlining the work in the callback leads to a deadlock with checkpoint if a
checkpoint begins before we call back into the ydb while processing _f.

#1059