Skip to content

Commit

Permalink
Merge pull request apache#1805 from merico-dev/fix#1799
Browse files Browse the repository at this point in the history
fix: handle empty primary key correctly
  • Loading branch information
klesh authored May 7, 2022
2 parents 62af8e6 + 3330040 commit 2d93add
Showing 1 changed file with 12 additions and 10 deletions.
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

0 comments on commit 2d93add

Please sign in to comment.