hotfix: Reduce memory usage when calculating commit graph
Created by: efritz
This PR cherry-picks updates from https://github.com/sourcegraph/sourcegraph/pull/16086 (off of main) into the 3.21 branch so that we can build an image for a customer who is currently experiencing memory pressure.