database: fix feature version cache

This commit is contained in:
Quentin Machu 2016-01-27 16:49:22 -05:00 committed by Jimmy Zelinskie
parent 40a7c8a00d
commit 35df7ca0eb

View File

@ -67,10 +67,10 @@ func (pgSQL *pgSQL) insertFeatureVersion(featureVersion database.FeatureVersion)
} }
// Do cache lookup. // Do cache lookup.
cacheIndex := "featureversion:" + featureVersion.Feature.Namespace.Name + ":" + featureVersion.Feature.Name + ":" + featureVersion.Version.String()
if pgSQL.cache != nil { if pgSQL.cache != nil {
promCacheQueriesTotal.WithLabelValues("featureversion").Inc() promCacheQueriesTotal.WithLabelValues("featureversion").Inc()
id, found := pgSQL.cache.Get("featureversion:" + featureVersion.Feature.Namespace.Name + ":" + id, found := pgSQL.cache.Get(cacheIndex)
featureVersion.Feature.Name + ":" + featureVersion.Version.String())
if found { if found {
promCacheHitsTotal.WithLabelValues("featureversion").Inc() promCacheHitsTotal.WithLabelValues("featureversion").Inc()
return id.(int), nil return id.(int), nil
@ -101,8 +101,8 @@ func (pgSQL *pgSQL) insertFeatureVersion(featureVersion database.FeatureVersion)
// Lock Vulnerability_Affects_FeatureVersion exclusively. // Lock Vulnerability_Affects_FeatureVersion exclusively.
// We want to prevent InsertVulnerability to modify it. // We want to prevent InsertVulnerability to modify it.
promConcurrentLockVAFV.Inc() promConcurrentLockVAFV.Inc()
defer promConcurrentLockVAFV.Dec() defer promConcurrentLockVAFV.Dec()
t = time.Now() t = time.Now()
_, err = tx.Exec(getQuery("l_vulnerability_affects_featureversion")) _, err = tx.Exec(getQuery("l_vulnerability_affects_featureversion"))
observeQueryTime("insertFeatureVersion", "lock", t) observeQueryTime("insertFeatureVersion", "lock", t)
@ -148,8 +148,7 @@ func (pgSQL *pgSQL) insertFeatureVersion(featureVersion database.FeatureVersion)
} }
if pgSQL.cache != nil { if pgSQL.cache != nil {
pgSQL.cache.Add("featureversion:"+featureVersion.Feature.Name+":"+ pgSQL.cache.Add(cacheIndex, featureVersion.ID)
featureVersion.Feature.Namespace.Name+":"+featureVersion.Version.String(), featureVersion.ID)
} }
return featureVersion.ID, nil return featureVersion.ID, nil