summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2018-12-11 09:09:46 +0800
committerGitHub <noreply@github.com>2018-12-11 09:09:46 +0800
commit284b0e12cb1f8d39693465bbcd94e6125eb3ca80 (patch)
tree0b9f83e2c1b0d8c95255da1063b240816e25d514 /models
parent8a64e67456641941aec3fa5250491c1a8b3c0830 (diff)
downloadgitea-284b0e12cb1f8d39693465bbcd94e6125eb3ca80.tar.gz
gitea-284b0e12cb1f8d39693465bbcd94e6125eb3ca80.zip
fix code review on mssql (#5502)
Diffstat (limited to 'models')
-rw-r--r--models/review.go26
1 files changed, 19 insertions, 7 deletions
diff --git a/models/review.go b/models/review.go
index 7eabb93746..3ae1dd457c 100644
--- a/models/review.go
+++ b/models/review.go
@@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
+ "github.com/go-xorm/core"
"github.com/go-xorm/xorm"
"github.com/go-xorm/builder"
@@ -266,13 +267,24 @@ type PullReviewersWithType struct {
// GetReviewersByPullID gets all reviewers for a pull request with the statuses
func GetReviewersByPullID(pullID int64) (issueReviewers []*PullReviewersWithType, err error) {
irs := []*PullReviewersWithType{}
- err = x.Select("`user`.*, review.type, max(review.updated_unix) as review_updated_unix").
- Table("review").
- Join("INNER", "`user`", "review.reviewer_id = `user`.id").
- Where("review.issue_id = ? AND (review.type = ? OR review.type = ?)", pullID, ReviewTypeApprove, ReviewTypeReject).
- GroupBy("`user`.id, review.type").
- OrderBy("review_updated_unix DESC").
- Find(&irs)
+ if x.Dialect().DBType() == core.MSSQL {
+ err = x.SQL(`SELECT [user].*, review.type, review.review_updated_unix FROM
+(SELECT review.id, review.type, review.reviewer_id, max(review.updated_unix) as review_updated_unix
+FROM review WHERE review.issue_id=? AND (review.type = ? OR review.type = ?)
+GROUP BY review.id, review.type, review.reviewer_id) as review
+INNER JOIN [user] ON review.reviewer_id = [user].id ORDER BY review_updated_unix DESC`,
+ pullID, ReviewTypeApprove, ReviewTypeReject).
+ Find(&irs)
+ } else {
+ err = x.Select("`user`.*, review.type, max(review.updated_unix) as review_updated_unix").
+ Table("review").
+ Join("INNER", "`user`", "review.reviewer_id = `user`.id").
+ Where("review.issue_id = ? AND (review.type = ? OR review.type = ?)",
+ pullID, ReviewTypeApprove, ReviewTypeReject).
+ GroupBy("`user`.id, review.type").
+ OrderBy("review_updated_unix DESC").
+ Find(&irs)
+ }
// We need to group our results by user id _and_ review type, otherwise the query fails when using postgresql.
// But becaus we're doing this, we need to manually filter out multiple reviews of different types by the