Skip to content

Commit

Permalink
Fix parameter mapping in leaderboard haystack query. Merge #76
Browse files Browse the repository at this point in the history
  • Loading branch information
zyro committed Jun 8, 2017
1 parent 07d97a4 commit 6815d69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [keep a changelog](http://keepachangelog.com/) and this p
### Fixed
- Update storage write permissions validation.
- Runtime module path must derive from `--data-dir` flag value.
- Fix parameter mapping in leaderboard haystack query.

## [0.13.0] - 2017-05-29
### Added
Expand Down
30 changes: 16 additions & 14 deletions server/pipeline_leaderboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,18 +663,19 @@ func (p *pipeline) loadLeaderboardRecordsHaystack(logger *zap.Logger, session *s
// First half.
count := len(params)
firstQuery := query
firstParams := params
firstParams := make([]interface{}, len(params))
copy(firstParams, params)
if sortOrder == 0 {
// Lower score is better, but get in reverse order from current user to get those immediately above.
firstQuery += " AND (score, updated_at_inverse, id) <= ($" + strconv.Itoa(count) +
", $" + strconv.Itoa(count+1) +
", $" + strconv.Itoa(count+2) + ") ORDER BY score DESC, updated_at_inverse DESC"
firstQuery += " AND (score, updated_at_inverse, id) <= ($" + strconv.Itoa(count+1) +
", $" + strconv.Itoa(count+2) +
", $" + strconv.Itoa(count+3) + ") ORDER BY score DESC, updated_at_inverse DESC"
firstParams = append(firstParams, score, invertMs(updatedAt), id)
} else {
// Higher score is better.
firstQuery += " AND (score, updated_at, id) >= ($" + strconv.Itoa(count) +
", $" + strconv.Itoa(count+1) +
", $" + strconv.Itoa(count+2) + ") ORDER BY score ASC, updated_at ASC"
firstQuery += " AND (score, updated_at, id) >= ($" + strconv.Itoa(count+1) +
", $" + strconv.Itoa(count+2) +
", $" + strconv.Itoa(count+3) + ") ORDER BY score ASC, updated_at ASC"
firstParams = append(firstParams, score, updatedAt, id)
}
firstParams = append(firstParams, int64(limit/2))
Expand Down Expand Up @@ -740,18 +741,19 @@ func (p *pipeline) loadLeaderboardRecordsHaystack(logger *zap.Logger, session *s

// Second half.
secondQuery := query
secondParams := params
secondParams := make([]interface{}, len(params))
copy(secondParams, params)
if sortOrder == 0 {
// Lower score is better.
secondQuery += " AND (score, updated_at, id) > ($" + strconv.Itoa(count) +
", $" + strconv.Itoa(count+1) +
", $" + strconv.Itoa(count+2) + ") ORDER BY score ASC, updated_at ASC"
secondQuery += " AND (score, updated_at, id) > ($" + strconv.Itoa(count+1) +
", $" + strconv.Itoa(count+2) +
", $" + strconv.Itoa(count+3) + ") ORDER BY score ASC, updated_at ASC"
secondParams = append(secondParams, score, updatedAt, id)
} else {
// Higher score is better.
secondQuery += " AND (score, updated_at_inverse, id) < ($" + strconv.Itoa(count) +
", $" + strconv.Itoa(count+1) +
", $" + strconv.Itoa(count+2) + ") ORDER BY score DESC, updated_at DESC"
secondQuery += " AND (score, updated_at_inverse, id) < ($" + strconv.Itoa(count+1) +
", $" + strconv.Itoa(count+2) +
", $" + strconv.Itoa(count+3) + ") ORDER BY score DESC, updated_at DESC"
secondParams = append(secondParams, score, invertMs(updatedAt), id)
}
secondParams = append(secondParams, limit-int64(len(leaderboardRecords))+2)
Expand Down

0 comments on commit 6815d69

Please sign in to comment.