diff options
author | Vincent Ambo <tazjin@google.com> | 2019-10-31T17·48+0000 |
---|---|---|
committer | Vincent Ambo <github@tazj.in> | 2019-11-03T01·33+0000 |
commit | 05b5b1718a4b9f251d51767a189905649ad42282 (patch) | |
tree | 6da37c245090ba7e0a73d0ae0bf0271f07ac033e /tools/nixery/popcount | |
parent | 6a2fb092a72be70c173b756e5cb2276a542a09df (diff) |
feat(popcount): Cache seen narinfos on disk
Diffstat (limited to 'tools/nixery/popcount')
-rw-r--r-- | tools/nixery/popcount/popcount.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tools/nixery/popcount/popcount.go b/tools/nixery/popcount/popcount.go index bc5f42af8a85..b21cee2e0e7d 100644 --- a/tools/nixery/popcount/popcount.go +++ b/tools/nixery/popcount/popcount.go @@ -160,6 +160,11 @@ func narInfoToRefs(narinfo string) []string { } func fetchNarInfo(i *item) (string, error) { + file, err := ioutil.ReadFile("popcache/" + i.hash) + if err == nil { + return string(file), nil + } + resp, err := client.Get(fmt.Sprintf("https://cache.nixos.org/%s.narinfo", i.hash)) if err != nil { return "", err @@ -168,6 +173,10 @@ func fetchNarInfo(i *item) (string, error) { defer resp.Body.Close() narinfo, err := ioutil.ReadAll(resp.Body) + + // best-effort write the file to the cache + ioutil.WriteFile("popcache/" + i.hash, narinfo, 0644) + return string(narinfo), err } @@ -208,6 +217,11 @@ func main() { log.Fatalf("Nix channel must be specified as first argument") } + err := os.MkdirAll("popcache", 0755) + if err != nil { + log.Fatalf("Failed to create 'popcache' directory in current folder: %s\n", err) + } + count := 42 // concurrent downloader count channel := os.Args[1] log.Printf("Fetching metadata for channel '%s'\n", channel) |