diff --git a/pkg/package/database_mem.go b/pkg/package/database_mem.go index c05084c3..8417aa09 100644 --- a/pkg/package/database_mem.go +++ b/pkg/package/database_mem.go @@ -213,6 +213,25 @@ func (db *InMemoryDatabase) populateCaches(p Package) { db.CacheNoVersion[p.GetPackageName()] = make(map[string]interface{}) } db.CacheNoVersion[p.GetPackageName()][p.GetVersion()] = nil + + // Updating Revdeps + // Given that when we populate the cache we don't have the full db at hand + // We cycle over reverse dependency of a package to update their entry if they are matching + // the version selector + toUpdate, ok := db.RevDepsDatabase[pd.GetPackageName()] + if ok { + for _, pp := range toUpdate { + for _, re := range pp.GetRequires() { + if match, _ := pd.VersionMatchSelector(re.GetVersion(), nil); match { + _, ok = db.RevDepsDatabase[pd.GetFingerPrint()] + if !ok { + db.RevDepsDatabase[pd.GetFingerPrint()] = make(map[string]Package) + } + db.RevDepsDatabase[pd.GetFingerPrint()][pp.GetFingerPrint()] = pp + } + } + } + } db.Unlock() for _, re := range pd.GetRequires() { @@ -225,12 +244,23 @@ func (db *InMemoryDatabase) populateCaches(p Package) { db.RevDepsDatabase[pa.GetFingerPrint()] = make(map[string]Package) } db.RevDepsDatabase[pa.GetFingerPrint()][pd.GetFingerPrint()] = pd + _, ok = db.RevDepsDatabase[pa.GetPackageName()] + if !ok { + db.RevDepsDatabase[pa.GetPackageName()] = make(map[string]Package) + } + db.RevDepsDatabase[pa.GetPackageName()][pd.GetPackageName()] = pd } _, ok := db.RevDepsDatabase[re.GetFingerPrint()] if !ok { db.RevDepsDatabase[re.GetFingerPrint()] = make(map[string]Package) } db.RevDepsDatabase[re.GetFingerPrint()][pd.GetFingerPrint()] = pd + _, ok = db.RevDepsDatabase[re.GetPackageName()] + if !ok { + db.RevDepsDatabase[re.GetPackageName()] = make(map[string]Package) + } + db.RevDepsDatabase[re.GetPackageName()][pd.GetPackageName()] = pd + db.Unlock() } }