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: handle empty primary key correctly #1805

Merged
merged 1 commit into from
May 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions plugins/helper/batch_save.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,20 @@ func (c *BatchSave) Add(slot interface{}) error {
}
// deduplication
key := getPrimaryKeyValue(slot)
if index, ok := c.valueIndex[key]; ok {
c.slots.Index(index).Set(reflect.ValueOf(slot))
} else {
// push into slot
c.valueIndex[key] = c.current
c.slots.Index(c.current).Set(reflect.ValueOf(slot))
c.current++
// flush out into database if max outed
if c.current == c.size {
return c.Flush()
if key != "" {
if index, ok := c.valueIndex[key]; !ok {
c.valueIndex[key] = c.current
} else {
c.slots.Index(index).Set(reflect.ValueOf(slot))
return nil
}
}
c.slots.Index(c.current).Set(reflect.ValueOf(slot))
c.current++
// flush out into database if max outed
if c.current == c.size {
return c.Flush()
}
return nil
}

Expand Down