Remove URLToPrefetch struct
This commit is contained in:
parent
a83ecf626b
commit
53d5b0f3cd
|
@ -32,7 +32,6 @@ const (
|
|||
|
||||
type Source struct {
|
||||
urls []string
|
||||
prefetch []*URLToPrefetch
|
||||
format SourceFormat
|
||||
in []byte
|
||||
minisignKey *minisign.PublicKey
|
||||
|
@ -134,10 +133,6 @@ func (source *Source) fetchWithCache(xTransport *XTransport, urlStr string) (bin
|
|||
return
|
||||
}
|
||||
|
||||
type URLToPrefetch struct {
|
||||
url string
|
||||
}
|
||||
|
||||
func NewSource(xTransport *XTransport, urls []string, minisignKeyStr string, cacheFile string, formatStr string, refreshDelay time.Duration) (source *Source, err error) {
|
||||
if refreshDelay < DefaultPrefetchDelay {
|
||||
refreshDelay = DefaultPrefetchDelay
|
||||
|
@ -154,29 +149,21 @@ func NewSource(xTransport *XTransport, urls []string, minisignKeyStr string, cac
|
|||
return source, err
|
||||
}
|
||||
now := timeNow()
|
||||
source.prefetch = []*URLToPrefetch{}
|
||||
|
||||
var bin, sig []byte
|
||||
var delayTillNextUpdate time.Duration
|
||||
var preloadURL string
|
||||
if len(urls) <= 0 {
|
||||
bin, sig, delayTillNextUpdate, err = source.fetchWithCache(xTransport, "")
|
||||
} else {
|
||||
preloadURL = urls[0]
|
||||
for _, url := range urls {
|
||||
bin, sig, delayTillNextUpdate, err = source.fetchWithCache(xTransport, url)
|
||||
if err == nil {
|
||||
preloadURL = url
|
||||
break
|
||||
}
|
||||
dlog.Infof("Loading from [%s] failed", url)
|
||||
}
|
||||
source.refresh = now.Add(delayTillNextUpdate)
|
||||
}
|
||||
if len(preloadURL) > 0 {
|
||||
url := preloadURL
|
||||
source.prefetch = append(source.prefetch, &URLToPrefetch{url: url})
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -196,17 +183,17 @@ func PrefetchSources(xTransport *XTransport, sources []*Source) time.Duration {
|
|||
if source.refresh.IsZero() {
|
||||
continue
|
||||
}
|
||||
for _, urlToPrefetch := range source.prefetch {
|
||||
for _, u := range source.urls {
|
||||
if source.refresh.After(now) {
|
||||
continue
|
||||
}
|
||||
dlog.Debugf("Prefetching [%s]", urlToPrefetch.url)
|
||||
_, _, delay, err := source.fetchWithCache(xTransport, urlToPrefetch.url)
|
||||
dlog.Debugf("Prefetching [%s]", u)
|
||||
_, _, delay, err := source.fetchWithCache(xTransport, u)
|
||||
if err != nil {
|
||||
dlog.Debugf("Prefetching [%s] failed: %v", urlToPrefetch.url, err)
|
||||
dlog.Debugf("Prefetching [%s] failed: %v", u, err)
|
||||
continue
|
||||
}
|
||||
dlog.Debugf("Prefetching [%s] succeeded. Next refresh scheduled for %v", urlToPrefetch.url, source.refresh)
|
||||
dlog.Debugf("Prefetching [%s] succeeded. Next refresh scheduled for %v", u, source.refresh)
|
||||
source.refresh = now.Add(delay)
|
||||
if delay >= MinimumPrefetchInterval && (interval == MinimumPrefetchInterval || interval > delay) {
|
||||
interval = delay
|
||||
|
|
|
@ -291,9 +291,6 @@ func prepSourceTestDownload(t *testing.T, d *SourceTestData, e *SourceTestExpect
|
|||
e.err = "parse"
|
||||
}
|
||||
e.Source.urls = append(e.Source.urls, d.server.URL+path)
|
||||
if state != TestStatePathErr {
|
||||
e.Source.prefetch = append(e.Source.prefetch, &URLToPrefetch{d.server.URL + path})
|
||||
}
|
||||
}
|
||||
if e.success {
|
||||
e.err = ""
|
||||
|
@ -310,7 +307,7 @@ func setupSourceTestCase(t *testing.T, d *SourceTestData, i int,
|
|||
cachePath: filepath.Join(d.tempDir, id),
|
||||
refresh: d.timeNow,
|
||||
}
|
||||
e.Source = &Source{urls: []string{}, prefetch: []*URLToPrefetch{}, format: SourceFormatV2, minisignKey: d.key,
|
||||
e.Source = &Source{urls: []string{}, format: SourceFormatV2, minisignKey: d.key,
|
||||
cacheFile: e.cachePath, cacheTTL: DefaultPrefetchDelay * 3, prefetchDelay: DefaultPrefetchDelay}
|
||||
if cacheTest != nil {
|
||||
prepSourceTestCache(t, d, e, d.sources[i], *cacheTest)
|
||||
|
|
Loading…
Reference in New Issue