#2895 minor fix for bug of xorm

This commit is contained in:
Unknwon 2016-04-26 00:22:03 -04:00
parent dfad51fe9e
commit 0325bec283
4 changed files with 35 additions and 31 deletions

View File

@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
##### Current version: 0.9.22 ##### Current version: 0.9.23
| Web | UI | Preview | | Web | UI | Preview |
|:-------------:|:-------:|:-------:| |:-------------:|:-------:|:-------:|

View File

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )
const APP_VER = "0.9.22.0425" const APP_VER = "0.9.23.0426"
func init() { func init() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

View File

@ -506,28 +506,28 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
sess := x.Limit(setting.IssuePagingNum, (opts.Page-1)*setting.IssuePagingNum) sess := x.Limit(setting.IssuePagingNum, (opts.Page-1)*setting.IssuePagingNum)
if opts.RepoID > 0 { if opts.RepoID > 0 {
sess.Where("issue.repo_id=?", opts.RepoID).And("issue.is_closed=?", opts.IsClosed) sess.Where("issue.repo_id=?", opts.RepoID).And("is_closed=?", opts.IsClosed)
} else if opts.RepoIDs != nil { } else if opts.RepoIDs != nil {
// In case repository IDs are provided but actually no repository has issue. // In case repository IDs are provided but actually no repository has issue.
if len(opts.RepoIDs) == 0 { if len(opts.RepoIDs) == 0 {
return make([]*Issue, 0), nil return make([]*Issue, 0), nil
} }
sess.In("repo_id", base.Int64sToStrings(opts.RepoIDs)).And("issue.is_closed=?", opts.IsClosed) sess.In("repo_id", base.Int64sToStrings(opts.RepoIDs)).And("is_closed=?", opts.IsClosed)
} else { } else {
sess.Where("issue.is_closed=?", opts.IsClosed) sess.Where("issue.is_closed=?", opts.IsClosed)
} }
if opts.AssigneeID > 0 { if opts.AssigneeID > 0 {
sess.And("issue.assignee_id=?", opts.AssigneeID) sess.And("assignee_id=?", opts.AssigneeID)
} else if opts.PosterID > 0 { } else if opts.PosterID > 0 {
sess.And("issue.poster_id=?", opts.PosterID) sess.And("poster_id=?", opts.PosterID)
} }
if opts.MilestoneID > 0 { if opts.MilestoneID > 0 {
sess.And("issue.milestone_id=?", opts.MilestoneID) sess.And("milestone_id=?", opts.MilestoneID)
} }
sess.And("issue.is_pull=?", opts.IsPull) sess.And("is_pull=?", opts.IsPull)
switch opts.SortType { switch opts.SortType {
case "oldest": case "oldest":
@ -546,13 +546,15 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
sess.Desc("created_unix") sess.Desc("created_unix")
} }
labelIDs := base.StringsToInt64s(strings.Split(opts.Labels, ",")) if opts.Labels != "0" {
if opts.Labels != "" && len(labelIDs) > 0 { labelIDs := base.StringsToInt64s(strings.Split(opts.Labels, ","))
sess.Join("INNER", "issue_label", "issue.id = issue_label.issue_id").In("issue_label.label_id", labelIDs) if opts.Labels != "" && len(labelIDs) > 0 {
sess.Join("INNER", "issue_label", "issue.id = issue_label.issue_id").In("label_id", labelIDs)
}
} }
if opts.IsMention { if opts.IsMention {
sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id").And("issue_user.is_mentioned = ?", true) sess.Join("INNER", "issue_user", "issue.id = issue_user.issue_id").And("is_mentioned = ?", true)
if opts.UserID > 0 { if opts.UserID > 0 {
sess.And("issue_user.uid = ?", opts.UserID) sess.And("issue_user.uid = ?", opts.UserID)
@ -781,11 +783,13 @@ func GetIssueStats(opts *IssueStatsOptions) *IssueStats {
stats := &IssueStats{} stats := &IssueStats{}
countSession := func(opts *IssueStatsOptions) *xorm.Session { countSession := func(opts *IssueStatsOptions) *xorm.Session {
sess := x.Where("issue.repo_id = ?", opts.RepoID).And("issue.is_pull = ?", opts.IsPull) sess := x.Where("issue.repo_id = ?", opts.RepoID).And("is_pull = ?", opts.IsPull)
labelIDs := base.StringsToInt64s(strings.Split(opts.Labels, ",")) if opts.Labels != "0" {
if opts.Labels != "" && len(labelIDs) > 0 { labelIDs := base.StringsToInt64s(strings.Split(opts.Labels, ","))
sess.Join("INNER", "issue_label", "issue.id = issue_label.issue_id").In("issue_label.label_id", labelIDs) if opts.Labels != "" && len(labelIDs) > 0 {
sess.Join("INNER", "issue_label", "issue.id = issue_id").In("label_id", labelIDs)
}
} }
if opts.MilestoneID > 0 { if opts.MilestoneID > 0 {
@ -802,35 +806,35 @@ func GetIssueStats(opts *IssueStatsOptions) *IssueStats {
switch opts.FilterMode { switch opts.FilterMode {
case FM_ALL, FM_ASSIGN: case FM_ALL, FM_ASSIGN:
stats.OpenCount, _ = countSession(opts). stats.OpenCount, _ = countSession(opts).
And("issue.is_closed = ?", false). And("is_closed = ?", false).
Count(&Issue{}) Count(&Issue{})
stats.ClosedCount, _ = countSession(opts). stats.ClosedCount, _ = countSession(opts).
And("issue.is_closed = ?", true). And("is_closed = ?", true).
Count(&Issue{}) Count(&Issue{})
case FM_CREATE: case FM_CREATE:
stats.OpenCount, _ = countSession(opts). stats.OpenCount, _ = countSession(opts).
And("poster_id = ?", opts.UserID). And("poster_id = ?", opts.UserID).
And("issue.is_closed = ?", false). And("is_closed = ?", false).
Count(&Issue{}) Count(&Issue{})
stats.ClosedCount, _ = countSession(opts). stats.ClosedCount, _ = countSession(opts).
And("poster_id = ?", opts.UserID). And("poster_id = ?", opts.UserID).
And("issue.is_closed = ?", true). And("is_closed = ?", true).
Count(&Issue{}) Count(&Issue{})
case FM_MENTION: case FM_MENTION:
stats.OpenCount, _ = countSession(opts). stats.OpenCount, _ = countSession(opts).
Join("INNER", "issue_user", "issue.id = issue_user.issue_id"). Join("INNER", "issue_user", "issue.id = issue_user.issue_id").
And("issue_user.uid = ?", opts.UserID). And("uid = ?", opts.UserID).
And("issue_user.is_mentioned = ?", true). And("is_mentioned = ?", true).
And("issue.is_closed = ?", false). And("is_closed = ?", false).
Count(&Issue{}) Count(&Issue{})
stats.ClosedCount, _ = countSession(opts). stats.ClosedCount, _ = countSession(opts).
Join("INNER", "issue_user", "issue.id = issue_user.issue_id"). Join("INNER", "issue_user", "issue.id = issue_user.issue_id").
And("issue_user.uid = ?", opts.UserID). And("uid = ?", opts.UserID).
And("issue_user.is_mentioned = ?", true). And("is_mentioned = ?", true).
And("issue.is_closed = ?", true). And("is_closed = ?", true).
Count(&Issue{}) Count(&Issue{})
} }
return stats return stats
@ -844,9 +848,9 @@ func GetUserIssueStats(repoID, uid int64, repoIDs []int64, filterMode int, isPul
sess := x.Where("issue.is_closed = ?", isClosed).And("issue.is_pull = ?", isPull) sess := x.Where("issue.is_closed = ?", isClosed).And("issue.is_pull = ?", isPull)
if repoID > 0 || len(repoIDs) == 0 { if repoID > 0 || len(repoIDs) == 0 {
sess.And("issue.repo_id = ?", repoID) sess.And("repo_id = ?", repoID)
} else { } else {
sess.In("issue.repo_id", repoIDs) sess.In("repo_id", repoIDs)
} }
return sess return sess
@ -882,8 +886,8 @@ func GetUserIssueStats(repoID, uid int64, repoIDs []int64, filterMode int, isPul
func GetRepoIssueStats(repoID, uid int64, filterMode int, isPull bool) (numOpen int64, numClosed int64) { func GetRepoIssueStats(repoID, uid int64, filterMode int, isPull bool) (numOpen int64, numClosed int64) {
countSession := func(isClosed, isPull bool, repoID int64) *xorm.Session { countSession := func(isClosed, isPull bool, repoID int64) *xorm.Session {
sess := x.Where("issue.repo_id = ?", isClosed). sess := x.Where("issue.repo_id = ?", isClosed).
And("issue.is_pull = ?", isPull). And("is_pull = ?", isPull).
And("issue.repo_id = ?", repoID) And("repo_id = ?", repoID)
return sess return sess
} }

View File

@ -1 +1 @@
0.9.22.0425 0.9.23.0426