Skip to content

maintenance: Call Optimize directly on repository manager

John Cai requested to merge jc-dont-call-optimize-repo into master

Currently, OptimizeRepository is called through an RPC to the gitaly instance. This is unnecessarily roundabout, however. We can just call the method directly.

This commit adds an OptimizerFunc that makes it easy for a caller to pass in a function to act as an Optimizer. We then pass in a direct call to OptimizeRepository from main.go.

In a preparatory commit, we change the signature of StartWorkers. StartWorkers() is meant to start backgorund workers. Currently however, its only used for repository optimization. In the future, there may be more workers that we would want to add to this method.

However, the current method makes that a bit difficult. If we have worker specific logic in the function body, then anytime that logic needs some other resource it will need to be passed in via function arguments.

This is true even if we want to change the implementation of an existing worker. In the next commit, we will change the implementation of OptimizeRepository, which requires a catfile cache, and a locator. Since StartWorkers() doesn't have access to these, they will need to be passed in.

Instead, introduce a new type Worker, which is just a function that takes a context and logger. This way, we decouple the implementation of the worker from StartWorkers().

fixes: #3990 (closed)

Edited by John Cai

Merge request reports