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

docstore: fix batch Creates #2726

Merged
merged 3 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions docstore/driver/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ func GroupActions(actions []*Action) (beforeGets, getList, writeList, afterGets
agets := map[interface{}]*Action{}
cgets := map[interface{}]*Action{}
writes := map[interface{}]*Action{}
var nilkeys []*Action
for _, a := range actions {
if a.Kind == Get {
if a.Key == nil {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe Key is not necessarily nil, it could be empty string. Probably better check a.Kind == Create

// Probably a Create.
nilkeys = append(nilkeys, a)
} else if a.Kind == Get {
// If there was a prior write with this key, make sure this get
// happens after the writes.
if _, ok := writes[a.Key]; ok {
Expand Down Expand Up @@ -91,7 +95,7 @@ func GroupActions(actions []*Action) (beforeGets, getList, writeList, afterGets
return as
}

return vals(bgets), vals(cgets), vals(writes), vals(agets)
return vals(bgets), vals(cgets), append(vals(writes), nilkeys...), vals(agets)
}

// AsFunc creates and returns an "as function" that behaves as follows:
Expand Down
9 changes: 7 additions & 2 deletions docstore/driver/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func TestGroupActions(t *testing.T) {
},
want: [][]int{{0}, {1}, {2, 3}, {4}},
},
{
in: []*Action{{Kind: Create}, {Kind: Create}, {Kind: Create}},
want: [][]int{nil, nil, {0, 1, 2}, nil},
},
} {
got := make([][]*Action, 4)
got[0], got[1], got[2], got[3] = GroupActions(test.in)
Expand All @@ -106,10 +110,11 @@ func TestGroupActions(t *testing.T) {
if a1.Kind != a2.Kind {
return a1.Kind < a2.Kind
}
return a1.Key.(int) < a2.Key.(int)
a1k, _ := a1.Key.(int)
a2k, _ := a2.Key.(int)
return a1k < a2k
}))
if diff != "" {

t.Errorf("%v: %s", test.in, diff)
}
}
Expand Down