Skip to content

Commit

Permalink
Merge pull request #128 from ioito/hotfix/qx-duplicate-remove
Browse files Browse the repository at this point in the history
fix: avoid remove duplicate db resource
  • Loading branch information
ioito authored May 29, 2024
2 parents 1e6d92f + b3c63dd commit 3da904b
Show file tree
Hide file tree
Showing 1,237 changed files with 422,933 additions and 2 deletions.
6 changes: 4 additions & 2 deletions util/compare/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func CompareSetsFunc(cs SCompareSet, removed interface{}, commonDB interface{},

errs := make([]error, 0)
newExtSetArray := make([]valueElement, 0)
duplicateMap := map[string]bool{}
for k, idx := range dupCheck {
if len(idx) > 1 {
if !storeDup {
Expand All @@ -119,6 +120,7 @@ func CompareSetsFunc(cs SCompareSet, removed interface{}, commonDB interface{},
dupArrays.Index(i).Set(extSetArray[idx[i]].value)
}
dupValue.SetMapIndex(reflect.ValueOf(k), dupArrays)
duplicateMap[k] = true
}
} else {
newExtSetArray = append(newExtSetArray, extSetArray[idx[0]])
Expand Down Expand Up @@ -151,7 +153,7 @@ func CompareSetsFunc(cs SCompareSet, removed interface{}, commonDB interface{},
i += 1
j += 1
} else if cmp < 0 {
if len(dbSetArray[i].key) > 0 {
if _, ok := duplicateMap[dbSetArray[i].key]; !ok && len(dbSetArray[i].key) > 0 {
newVal := reflect.Append(removedValue, dbSetArray[i].value)
removedValue.Set(newVal)
}
Expand All @@ -166,7 +168,7 @@ func CompareSetsFunc(cs SCompareSet, removed interface{}, commonDB interface{},
addedValue.Set(newVal)
j += 1
} else if j >= len(extSetArray) {
if len(dbSetArray[i].key) > 0 {
if _, ok := duplicateMap[dbSetArray[i].key]; !ok && len(dbSetArray[i].key) > 0 {
newVal := reflect.Append(removedValue, dbSetArray[i].value)
removedValue.Set(newVal)
}
Expand Down
21 changes: 21 additions & 0 deletions util/compare/compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,27 @@ func TestCompareSets2(t *testing.T) {
added: []string{"6"},
duplicated: []string{"7"},
},
{
db: []LocalRes{
{Name: "1", ExternalId: ""},
{Name: "2", ExternalId: "2"},
{Name: "3", ExternalId: "3"},
{Name: "4", ExternalId: "4"},
{Name: "5", ExternalId: "5"},
{Name: "7", ExternalId: "7"},
},
remote: []RemoteRes{
{Name: "2", GlobalId: "2"},
{Name: "4", GlobalId: "4"},
{Name: "6", GlobalId: "6"},
{Name: "7-1", GlobalId: "7"},
{Name: "7-2", GlobalId: "7"},
},
common: []string{"2", "4"},
removed: []string{"3", "5"},
added: []string{"6"},
duplicated: []string{"7"},
},
}
for _, d := range data {
removed := []LocalRes{}
Expand Down
14 changes: 14 additions & 0 deletions vendor/github.com/beevik/etree/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions vendor/github.com/beevik/etree/CONTRIBUTORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions vendor/github.com/beevik/etree/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

205 changes: 205 additions & 0 deletions vendor/github.com/beevik/etree/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3da904b

Please sign in to comment.