Homestyx hydra

R1:d86bb086cac3

Reduce initial discovery from O(branches * commits) to O(commits)

Summary:
Fixes T4414. Currently, when we discover a new repository, we do something like this:

foreach (branch) {
foreach (commit on this branch) {
do_something();
}
}

In cases where there are a lot of branches which mostly just branch `master`, this leads to us doing roughly `O(branches * commits)` work.

We have a `commitCache` to prevent this, but it has two problems:

- It only fills out of the DB, and we do this…
Repository: R1 hydra
Commit Date: Feb 28 2014