Skip to content

Commit

Permalink
Remove uncessary branching
Browse files Browse the repository at this point in the history
  • Loading branch information
mpchadwick committed Nov 4, 2020
1 parent 1e234aa commit 4d3b07a
Showing 1 changed file with 23 additions and 40 deletions.
63 changes: 23 additions & 40 deletions src/eav.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,47 +32,30 @@ func (eav Eav) processInsert (s string) {
stmt, _ := sqlparser.Parse(s)
insert := stmt.(*sqlparser.Insert)

table := insert.Table.Name.String()
if table == "eav_entity_type" {
var entityTypeId string
rows := insert.Rows.(sqlparser.Values)
for _, vt := range rows {
for i, e := range vt {
column := currentTable[i]
switch v := e.(type) {
case *sqlparser.SQLVal:
if column == "entity_type_id" {
entityTypeId = string(v.Val)
}
if column == "entity_type_code" {
eav.entityMap[string(v.Val)] = entityTypeId
}
var entityTypeId string
var attributeId string

rows := insert.Rows.(sqlparser.Values)
for _, vt := range rows {
for i, e := range vt {
column := currentTable[i]
switch v := e.(type) {
case *sqlparser.SQLVal:
if column == "attribute_id" {
attributeId = string(v.Val)
}
}
}
}
if table == "eav_attribute" {
var attributeId string
var entityTypeId string
rows := insert.Rows.(sqlparser.Values)
for _, vt := range rows {
for i, e := range vt {
column := currentTable[i]
switch v := e.(type) {
case *sqlparser.SQLVal:
if column == "attribute_id" {
attributeId = string(v.Val)
}
if column == "entity_type_id" {
entityTypeId = string(v.Val)
}
if column == "attribute_code" {
for _, eavConfig := range eav.Config.Eav {
if eav.entityMap[eavConfig.Name] == entityTypeId {
for eavK, eavV := range eavConfig.Attributes {
if eavK == string(v.Val) {
eavConfig.Attributes[attributeId] = eavV
}
if column == "entity_type_id" {
entityTypeId = string(v.Val)
}
if column == "entity_type_code" {
eav.entityMap[string(v.Val)] = entityTypeId
}
if column == "attribute_code" {
for _, eavConfig := range eav.Config.Eav {
if eav.entityMap[eavConfig.Name] == entityTypeId {
for eavK, eavV := range eavConfig.Attributes {
if eavK == string(v.Val) {
eavConfig.Attributes[attributeId] = eavV
}
}
}
Expand Down

0 comments on commit 4d3b07a

Please sign in to comment.