Be sure to cache packages with same fingerprint only once

this makes sure that we are fast to process also invalid trees
This commit is contained in:
Ettore Di Giacinto
2021-01-12 01:26:19 +01:00
parent 40fc948c6e
commit bd3e483f0f

View File

@@ -41,6 +41,7 @@ type InMemoryDatabase struct {
CacheNoVersion map[string]map[string]interface{} CacheNoVersion map[string]map[string]interface{}
ProvidesDatabase map[string]map[string]Package ProvidesDatabase map[string]map[string]Package
RevDepsDatabase map[string]map[string]Package RevDepsDatabase map[string]map[string]Package
cached map[string]interface{}
} }
func NewInMemoryDatabase(singleton bool) PackageDatabase { func NewInMemoryDatabase(singleton bool) PackageDatabase {
@@ -53,6 +54,7 @@ func NewInMemoryDatabase(singleton bool) PackageDatabase {
CacheNoVersion: map[string]map[string]interface{}{}, CacheNoVersion: map[string]map[string]interface{}{},
ProvidesDatabase: map[string]map[string]Package{}, ProvidesDatabase: map[string]map[string]Package{},
RevDepsDatabase: map[string]map[string]Package{}, RevDepsDatabase: map[string]map[string]Package{},
cached: map[string]interface{}{},
} }
} }
return DBInMemoryInstance return DBInMemoryInstance
@@ -197,6 +199,11 @@ func (db *InMemoryDatabase) populateCaches(p Package) {
// Create extra cache between package -> []versions // Create extra cache between package -> []versions
db.Lock() db.Lock()
if _, ok := db.cached[p.GetFingerPrint()]; ok {
db.Unlock()
return
}
db.cached[p.GetFingerPrint()] = nil
// Provides: Store package provides, we will reuse this when walking deps // Provides: Store package provides, we will reuse this when walking deps
for _, provide := range pd.Provides { for _, provide := range pd.Provides {