maintenance: Refactor code to be more easily testable
This MR converts maintenance-related code in the repository service to be more easily testable. This is in preparation for the introduction of an extended OptimizeRepository RPC call.
Part of #2721 (closed)
Edited by Patrick Steinhardt