Skip to content

Commit

Permalink
fix bug from bug fix (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaoz authored Nov 6, 2021
1 parent 6c351c7 commit 91ce2a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions storage/data/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ func testFeedback(t *testing.T, db Database) {
result, err = db.GetUserItemFeedback("100", "8")
assert.NoError(t, err)
assert.Empty(t, result)

// insert valid feedback and invalid feedback at the same time
err = db.BatchInsertFeedback([]Feedback{
{FeedbackKey: FeedbackKey{"a", "0", "8"}},
{FeedbackKey: FeedbackKey{"a", "100", "200"}},
}, false, false, false)
assert.NoError(t, err)
}

func testItems(t *testing.T, db Database) {
Expand Down
8 changes: 4 additions & 4 deletions storage/data/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,11 @@ func (d *SQLDatabase) BatchInsertFeedback(feedback []Feedback, insertUser, inser
builder.WriteString("INSERT INTO feedback(feedback_type, user_id, item_id, time_stamp, comment) VALUES ")
}
var args []interface{}
for i, f := range feedback {
for _, f := range feedback {
if users.Has(f.UserId) && items.Has(f.ItemId) {
if len(args) > 0 {
builder.WriteString(",")
}
switch d.driver {
case MySQL:
builder.WriteString("(?,?,?,?,?)")
Expand All @@ -1082,9 +1085,6 @@ func (d *SQLDatabase) BatchInsertFeedback(feedback []Feedback, insertUser, inser
builder.WriteString(fmt.Sprintf("($%d,$%d,$%d,$%d,$%d)",
len(args)+1, len(args)+2, len(args)+3, len(args)+4, len(args)+5))
}
if i+1 < len(feedback) {
builder.WriteString(",")
}
args = append(args, f.FeedbackType, f.UserId, f.ItemId, f.Timestamp, f.Comment)
}
}
Expand Down

0 comments on commit 91ce2a1

Please sign in to comment.