feat(popcount): Cache seen narinfos on disk
This commit is contained in:
parent
6a2fb092a7
commit
05b5b1718a
1 changed files with 14 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue