|
5 | 5 | "fmt"
|
6 | 6 | "io"
|
7 | 7 | "net/http"
|
| 8 | + "slices" |
| 9 | + "strings" |
8 | 10 | "sync"
|
9 | 11 | "time"
|
10 | 12 |
|
@@ -107,13 +109,30 @@ func (p *Package) fetchNarInfoStatusOnce(output string) (bool, error) {
|
107 | 109 | type inCacheFunc func() (bool, error)
|
108 | 110 | f, ok := narInfoStatusFnCache.Load(p.Raw)
|
109 | 111 | if !ok {
|
110 |
| - key := fmt.Sprintf("%s^%s", p.Raw, output) |
111 | 112 | f = inCacheFunc(sync.OnceValues(func() (bool, error) { return p.fetchNarInfoStatus(output) }))
|
112 |
| - f, _ = narInfoStatusFnCache.LoadOrStore(key, f) |
| 113 | + f, _ = narInfoStatusFnCache.LoadOrStore(p.keyForOutput(output), f) |
113 | 114 | }
|
114 | 115 | return f.(inCacheFunc)()
|
115 | 116 | }
|
116 | 117 |
|
| 118 | +func (p *Package) keyForOutput(output string) string { |
| 119 | + if output == useDefaultOutput { |
| 120 | + sysInfo, err := p.sysInfoIfExists() |
| 121 | + // let's be super safe to always avoid empty key. |
| 122 | + if err == nil && sysInfo != nil && len(sysInfo.DefaultOutputs()) > 0 { |
| 123 | + names := make([]string, len(sysInfo.DefaultOutputs())) |
| 124 | + for i, o := range sysInfo.DefaultOutputs() { |
| 125 | + names[i] = o.Name |
| 126 | + } |
| 127 | + slices.Sort(names) |
| 128 | + output = strings.Join(names, ",") |
| 129 | + } |
| 130 | + } |
| 131 | + fmt.Println("output: ", output) |
| 132 | + |
| 133 | + return fmt.Sprintf("%s^%s", p.Raw, output) |
| 134 | +} |
| 135 | + |
117 | 136 | // fetchNarInfoStatus fetches the cache status for the package. It returns
|
118 | 137 | // true if cache exists, false otherwise.
|
119 | 138 | // NOTE: This function always performs an HTTP request and should not be called
|
|
0 commit comments