Skip to content

Commit

Permalink
database: fix cache collision (feature & feature versions)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-M authored and jzelinskie committed Feb 24, 2016
1 parent 99de759 commit 248fc7d
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions database/pgsql/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func (pgSQL *pgSQL) insertFeature(feature database.Feature) (int, error) {
}

if pgSQL.cache != nil {
if id, found := pgSQL.cache.Get("feature:" + feature.Name); found {
id, found := pgSQL.cache.Get("feature:" + feature.Namespace.Name + ":" + feature.Name)
if found {
return id.(int), nil
}
}
Expand All @@ -47,7 +48,7 @@ func (pgSQL *pgSQL) insertFeature(feature database.Feature) (int, error) {
}

if pgSQL.cache != nil {
pgSQL.cache.Add("feature:"+feature.Name, id)
pgSQL.cache.Add("feature:"+feature.Namespace.Name+":"+feature.Name, id)
}

return id, nil
Expand All @@ -59,8 +60,9 @@ func (pgSQL *pgSQL) insertFeatureVersion(featureVersion database.FeatureVersion)
}

if pgSQL.cache != nil {
if id, found := pgSQL.cache.Get("featureversion:" + featureVersion.Feature.Name + ":" +
featureVersion.Version.String()); found {
id, found := pgSQL.cache.Get("featureversion:" + featureVersion.Feature.Namespace.Name + ":" +
featureVersion.Feature.Name + ":" + featureVersion.Version.String())
if found {
return id.(int), nil
}
}
Expand Down Expand Up @@ -118,7 +120,7 @@ func (pgSQL *pgSQL) insertFeatureVersion(featureVersion database.FeatureVersion)

if pgSQL.cache != nil {
pgSQL.cache.Add("featureversion:"+featureVersion.Feature.Name+":"+
featureVersion.Version.String(), featureVersion.ID)
featureVersion.Feature.Namespace.Name+":"+featureVersion.Version.String(), featureVersion.ID)
}

return featureVersion.ID, nil
Expand Down

0 comments on commit 248fc7d

Please sign in to comment.