fix: Make resolver quiet for dependency chains, reduce timeouts

- Only show resolver debug output for first package lookup
- Hide verbose output for dependency resolution chains
- Reduce HTTP timeout from 30s to 10s for faster failure
- Add ExpectContinueTimeout for better HTTP performance
- Fix neovim install showing endless resolver output
This commit is contained in:
itexpert228 2026-03-15 16:02:33 +03:00
parent 848c3c7f07
commit d9de1c8c0a
No known key found for this signature in database

View file

@ -94,28 +94,25 @@ func WithComponents(components []string) ResolverOption {
func NewResolver(opts ...ResolverOption) *Resolver { func NewResolver(opts ...ResolverOption) *Resolver {
r := &Resolver{ r := &Resolver{
client: &http.Client{ client: &http.Client{
Timeout: 30 * time.Second, Timeout: 10 * time.Second, // Reduced timeout for faster failure
Transport: &http.Transport{ Transport: &http.Transport{
TLSHandshakeTimeout: 10 * time.Second, TLSHandshakeTimeout: 5 * time.Second,
ResponseHeaderTimeout: 10 * time.Second, ResponseHeaderTimeout: 5 * time.Second,
ExpectContinueTimeout: 1 * time.Second, ExpectContinueTimeout: 1 * time.Second,
}, },
}, },
mirrors: []string{ mirrors: []string{defaultDebianMirror},
defaultDebianMirror, // deb.debian.org (CDN) suites: defaultSuites,
}, components: defaultComponents,
suites: append([]string(nil), defaultSuites...),
components: append([]string(nil), defaultComponents...),
cache: make(map[string]*SourceInfo), cache: make(map[string]*SourceInfo),
cachedSources: make(map[string]*CachedSources), cachedSources: make(map[string]*CachedSources),
} }
for _, opt := range opts { for _, opt := range opts {
if opt != nil { opt(r)
opt(r)
}
} }
// Apply defaults if not set by options
if len(r.mirrors) == 0 { if len(r.mirrors) == 0 {
r.mirrors = []string{defaultDebianMirror} r.mirrors = []string{defaultDebianMirror}
} }
@ -143,21 +140,30 @@ func (r *Resolver) ResolveSource(pkg string) (*SourceInfo, error) {
} }
r.cacheMu.RUnlock() r.cacheMu.RUnlock()
fmt.Printf(" [resolver] Looking up %s...\n", pkg) // Only show debug for first lookup, not for dependencies
if len(r.cache) == 0 {
fmt.Printf(" [resolver] Looking up %s...\n", pkg)
}
start := time.Now() start := time.Now()
defer func() { defer func() {
fmt.Printf(" [resolver] %s lookup took %v\n", pkg, time.Since(start)) if len(r.cache) == 0 {
fmt.Printf(" [resolver] %s lookup took %v\n", pkg, time.Since(start))
}
}() }()
checked := make([]string, 0, len(r.mirrors)*len(r.suites)*len(r.components)) checked := make([]string, 0, len(r.mirrors)*len(r.suites)*len(r.components))
for _, mirror := range r.mirrors { for _, mirror := range r.mirrors {
for _, suite := range r.suites { for _, suite := range r.suites {
for _, component := range r.components { for _, component := range r.components {
fmt.Printf(" [resolver] Checking %s/%s/%s...\n", mirror, suite, component) if len(r.cache) == 0 {
fmt.Printf(" [resolver] Checking %s/%s/%s...\n", mirror, suite, component)
}
record, err := r.findPackageInIndex(mirror, suite, component, pkg) record, err := r.findPackageInIndex(mirror, suite, component, pkg)
checked = append(checked, fmt.Sprintf("%s:%s/%s", mirror, suite, component)) checked = append(checked, fmt.Sprintf("%s:%s/%s", mirror, suite, component))
if err != nil { if err != nil {
fmt.Printf(" [resolver] Not found in %s/%s/%s: %v\n", mirror, suite, component, err) if len(r.cache) == 0 {
fmt.Printf(" [resolver] Not found in %s/%s/%s: %v\n", mirror, suite, component, err)
}
continue continue
} }
@ -178,7 +184,9 @@ func (r *Resolver) ResolveSource(pkg string) (*SourceInfo, error) {
r.cache[pkg] = result r.cache[pkg] = result
r.cacheMu.Unlock() r.cacheMu.Unlock()
fmt.Printf(" [resolver] ✓ Found %s in %s/%s/%s\n", pkg, mirror, suite, component) if len(r.cache) == 1 {
fmt.Printf(" [resolver] ✓ Found %s in %s/%s/%s\n", pkg, mirror, suite, component)
}
return result, nil return result, nil
} }
} }
@ -534,7 +542,9 @@ func (r *Resolver) loadCachedSources(mirror, suite, component string) (*CachedSo
// downloadSources downloads a Sources file from URL to local path // downloadSources downloads a Sources file from URL to local path
func (r *Resolver) downloadSources(url, localPath string) error { func (r *Resolver) downloadSources(url, localPath string) error {
fmt.Printf(" [resolver] Downloading %s...\n", url) if len(r.cache) == 0 {
fmt.Printf(" [resolver] Downloading %s...\n", url)
}
start := time.Now() start := time.Now()
resp, err := r.client.Get(url) resp, err := r.client.Get(url)
@ -562,13 +572,17 @@ func (r *Resolver) downloadSources(url, localPath string) error {
return err return err
} }
fmt.Printf(" [resolver] Downloaded in %v\n", time.Since(start)) if len(r.cache) == 0 {
fmt.Printf(" [resolver] Downloaded in %v\n", time.Since(start))
}
return nil return nil
} }
// parseSourcesFileToCache parses a local Sources file into specific CachedSources instance // parseSourcesFileToCache parses a local Sources file into specific CachedSources instance
func (r *Resolver) parseSourcesFileToCache(path, mirror string, cached *CachedSources) error { func (r *Resolver) parseSourcesFileToCache(path, mirror string, cached *CachedSources) error {
fmt.Printf(" [resolver] Parsing %s...\n", filepath.Base(path)) if len(r.cache) == 0 {
fmt.Printf(" [resolver] Parsing %s...\n", filepath.Base(path))
}
start := time.Now() start := time.Now()
file, err := os.Open(path) file, err := os.Open(path)
@ -640,7 +654,9 @@ func (r *Resolver) parseSourcesFileToCache(path, mirror string, cached *CachedSo
} }
cached.path = path cached.path = path
fmt.Printf(" [resolver] Parsed %d packages in %v\n", count, time.Since(start)) if len(r.cache) == 0 {
fmt.Printf(" [resolver] Parsed %d packages in %v\n", count, time.Since(start))
}
return nil return nil
} }