From 4d3b07aad89dd052fd100b6bbe03ad3275cb2e0b Mon Sep 17 00:00:00 2001 From: Max Chadwick Date: Tue, 3 Nov 2020 22:11:25 -0500 Subject: [PATCH] Remove uncessary branching --- src/eav.go | 63 ++++++++++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 40 deletions(-) diff --git a/src/eav.go b/src/eav.go index 6238a35..3fb7f46 100644 --- a/src/eav.go +++ b/src/eav.go @@ -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 } } }