Use struct as a map key instead of string
String was used when Feature contains PotentialNamespace. Since it was moved to LayerFeature we can use struct as map key instead of string.
This commit is contained in:
parent
a8a91379d9
commit
d77dc0f0ae
@ -17,7 +17,6 @@ package pgsql
|
||||
import (
|
||||
"database/sql"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/lib/pq"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@ -312,7 +311,7 @@ func (tx *pgSession) findNamespacedFeatureIDs(nfs []database.NamespacedFeature)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
nfsMap := map[string]int64{}
|
||||
nfsMap := map[database.NamespacedFeature]int64{}
|
||||
keys := make([]interface{}, 0, len(nfs)*5)
|
||||
for _, nf := range nfs {
|
||||
keys = append(keys, nf.Name, nf.Version, nf.VersionFormat, nf.Type, nf.Namespace.Name)
|
||||
@ -335,12 +334,12 @@ func (tx *pgSession) findNamespacedFeatureIDs(nfs []database.NamespacedFeature)
|
||||
if err != nil {
|
||||
return nil, handleError("searchNamespacedFeature", err)
|
||||
}
|
||||
nfsMap[nf.Key()] = id
|
||||
nfsMap[nf] = id
|
||||
}
|
||||
|
||||
ids := make([]sql.NullInt64, len(nfs))
|
||||
for i, nf := range nfs {
|
||||
if id, ok := nfsMap[nf.Key()]; ok {
|
||||
if id, ok := nfsMap[nf]; ok {
|
||||
ids[i] = sql.NullInt64{id, true}
|
||||
} else {
|
||||
ids[i] = sql.NullInt64{}
|
||||
@ -360,14 +359,13 @@ func (tx *pgSession) findFeatureIDs(fs []database.Feature) ([]sql.NullInt64, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fMap := map[string]sql.NullInt64{}
|
||||
fMap := map[database.Feature]sql.NullInt64{}
|
||||
|
||||
keys := make([]interface{}, 0, len(fs)*4)
|
||||
for _, f := range fs {
|
||||
typeID := types.byName[f.Type]
|
||||
keys = append(keys, f.Name, f.Version, f.VersionFormat, typeID)
|
||||
mapKey := f.Name + f.Version + f.VersionFormat + strconv.Itoa(typeID)
|
||||
fMap[mapKey] = sql.NullInt64{}
|
||||
fMap[f] = sql.NullInt64{}
|
||||
}
|
||||
|
||||
rows, err := tx.Query(querySearchFeatureID(len(fs)), keys...)
|
||||
@ -388,15 +386,12 @@ func (tx *pgSession) findFeatureIDs(fs []database.Feature) ([]sql.NullInt64, err
|
||||
}
|
||||
|
||||
f.Type = types.byID[typeID]
|
||||
mapKey := f.Name + f.Version + f.VersionFormat + strconv.Itoa(typeID)
|
||||
fMap[mapKey] = id
|
||||
fMap[f] = id
|
||||
}
|
||||
|
||||
ids := make([]sql.NullInt64, len(fs))
|
||||
for i, f := range fs {
|
||||
typeID := types.byName[f.Type]
|
||||
mapKey := f.Name + f.Version + f.VersionFormat + strconv.Itoa(typeID)
|
||||
ids[i] = fMap[mapKey]
|
||||
ids[i] = fMap[f]
|
||||
}
|
||||
|
||||
return ids, nil
|
||||
|
Loading…
Reference in New Issue
Block a user