fix: reduce the fetches a little
@@ -135,6 +135,7 @@ func (f *gitFileBrowser) getOrCreateClient(owner string, repo string) *repoClien
if client == nil {
client = &repoClientFacade{
fullName: fullName,
+ pullTimes: map[string]int64{},
}
f.clients[fullName] = client
}
@@ -149,7 +150,7 @@ type repoClientFacade struct {
fullName string
mainBranch string
ref string
- refPullTime int64
+ pullTimes map[string]int64
}
var (
@@ -167,20 +168,20 @@ func (c *repoClientFacade) UseRef(ref string) error {
if strings.HasPrefix(ref, "refs/heads/") {
ref = "origin/" + strings.TrimPrefix(ref, "refs/heads/")
}
+ key := c.fullName + "/" + ref
if c.ref == ref {
t := time.Now().Unix()
+
// lets only re-run a git fetch of the ref if we've not done it for a little while
- if t-c.refPullTime < maxRefFetchSeconds {
+ if t-c.pullTimes[key] < maxRefFetchSeconds {
return nil
}
- c.refPullTime = t
+ c.pullTimes[key] = t
logrus.StandardLogger().WithFields(map[string]interface{}{
"Name": c.fullName,
"Ref": ref,
"File": "git_file_browser",
}).Info("fetching ref")
- } else {
- c.refPullTime = 0
}
// lets switch to the main branch first before we go to a custom sha/ref
