mirror of
https://github.com/tweag/gomod2nix.git
synced 2024-11-23 05:34:50 +00:00
fetch.go: Only use a singular cache instance
This commit is contained in:
parent
12916dd856
commit
a5c4020da8
1 changed files with 15 additions and 22 deletions
|
@ -30,7 +30,7 @@ type packageResult struct {
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func worker(id int, caches []map[string]*types.Package, jobs <-chan *packageJob, results chan<- *packageResult) {
|
func worker(id int, cache map[string]*types.Package, jobs <-chan *packageJob, results chan<- *packageResult) {
|
||||||
log.WithField("workerId", id).Info("Starting worker process")
|
log.WithField("workerId", id).Info("Starting worker process")
|
||||||
|
|
||||||
for j := range jobs {
|
for j := range jobs {
|
||||||
|
@ -39,7 +39,7 @@ func worker(id int, caches []map[string]*types.Package, jobs <-chan *packageJob,
|
||||||
"goPackagePath": j.goPackagePath,
|
"goPackagePath": j.goPackagePath,
|
||||||
}).Info("Worker received job")
|
}).Info("Worker received job")
|
||||||
|
|
||||||
pkg, err := fetchPackage(caches, j.importPath, j.goPackagePath, j.sumVersion)
|
pkg, err := fetchPackage(cache, j.importPath, j.goPackagePath, j.sumVersion)
|
||||||
results <- &packageResult{
|
results <- &packageResult{
|
||||||
err: err,
|
err: err,
|
||||||
pkg: pkg,
|
pkg: pkg,
|
||||||
|
@ -65,11 +65,7 @@ func FetchPackages(goModPath string, goSumPath string, goMod2NixPath string, num
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
caches := []map[string]*types.Package{}
|
caches := gomod2nix.LoadGomod2Nix(goMod2NixPath)
|
||||||
goModCache := gomod2nix.LoadGomod2Nix(goMod2NixPath)
|
|
||||||
if len(goModCache) > 0 {
|
|
||||||
caches = append(caches, goModCache)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map repos -> replacement repo
|
// Map repos -> replacement repo
|
||||||
replace := make(map[string]string)
|
replace := make(map[string]string)
|
||||||
|
@ -147,7 +143,7 @@ func FetchPackages(goModPath string, goSumPath string, goMod2NixPath string, num
|
||||||
return pkgs, nil
|
return pkgs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchPackage(caches []map[string]*types.Package, importPath string, goPackagePath string, sumVersion string) (*types.Package, error) {
|
func fetchPackage(cache map[string]*types.Package, importPath string, goPackagePath string, sumVersion string) (*types.Package, error) {
|
||||||
repoRoot, err := vcs.RepoRootForImportPath(importPath, false)
|
repoRoot, err := vcs.RepoRootForImportPath(importPath, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -167,12 +163,10 @@ func fetchPackage(caches []map[string]*types.Package, importPath string, goPacka
|
||||||
relPath = ""
|
relPath = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(caches) > 0 {
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"goPackagePath": goPackagePath,
|
"goPackagePath": goPackagePath,
|
||||||
}).Info("Checking previous invocation cache")
|
}).Info("Checking previous invocation cache")
|
||||||
|
{
|
||||||
for _, cache := range caches {
|
|
||||||
cached, ok := cache[goPackagePath]
|
cached, ok := cache[goPackagePath]
|
||||||
if ok {
|
if ok {
|
||||||
if cached.SumVersion == sumVersion {
|
if cached.SumVersion == sumVersion {
|
||||||
|
@ -183,7 +177,6 @@ func fetchPackage(caches []map[string]*types.Package, importPath string, goPacka
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if repoRoot.VCS.Name != "Git" {
|
if repoRoot.VCS.Name != "Git" {
|
||||||
return nil, fmt.Errorf("Only git repositories are supported")
|
return nil, fmt.Errorf("Only git repositories are supported")
|
||||||
|
|
Loading…
Reference in a new issue