Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid remove duplicate db resource #128

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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
Loading