mirror of
https://github.com/go-gitea/gitea.git
synced 2024-12-19 06:23:42 +08:00
refactor: use xorm builder
This commit is contained in:
parent
eff4d3024c
commit
f2ae3bdc01
|
@ -6,7 +6,6 @@ package issues
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
project_model "code.gitea.io/gitea/models/project"
|
project_model "code.gitea.io/gitea/models/project"
|
||||||
|
@ -34,11 +33,6 @@ func (issues IssueList) getRepoIDs() []int64 {
|
||||||
return repoIDs.Values()
|
return repoIDs.Values()
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the repoIDs from getRepoIDs as a comma-separator string like "5,7,8"
|
|
||||||
func (issues IssueList) getRepoIDsAsString() string {
|
|
||||||
return strings.Trim(strings.Join(strings.Fields(fmt.Sprint(issues.getRepoIDs())), ","), "[]")
|
|
||||||
}
|
|
||||||
|
|
||||||
// LoadRepositories loads issues' all repositories
|
// LoadRepositories loads issues' all repositories
|
||||||
func (issues IssueList) LoadRepositories(ctx context.Context) (repo_model.RepositoryList, error) {
|
func (issues IssueList) LoadRepositories(ctx context.Context) (repo_model.RepositoryList, error) {
|
||||||
if len(issues) == 0 {
|
if len(issues) == 0 {
|
||||||
|
@ -145,10 +139,6 @@ func (issues IssueList) getIssueIDs() []int64 {
|
||||||
return ids
|
return ids
|
||||||
}
|
}
|
||||||
|
|
||||||
func (issues IssueList) getIssueIDsAsString() string {
|
|
||||||
return strings.Trim(strings.Join(strings.Fields(fmt.Sprint(issues.getIssueIDs())), ","), "[]")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (issues IssueList) loadLabels(ctx context.Context) error {
|
func (issues IssueList) loadLabels(ctx context.Context) error {
|
||||||
if len(issues) == 0 {
|
if len(issues) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
@ -617,9 +607,10 @@ func (issues IssueList) BlockingDependenciesMap(ctx context.Context) (issueDepsM
|
||||||
Table("issue").
|
Table("issue").
|
||||||
Join("INNER", "repository", "repository.id = issue.repo_id").
|
Join("INNER", "repository", "repository.id = issue.repo_id").
|
||||||
Join("INNER", "issue_dependency", "issue_dependency.issue_id = issue.id").
|
Join("INNER", "issue_dependency", "issue_dependency.issue_id = issue.id").
|
||||||
Where(fmt.Sprintf("dependency_id IN (%s)", issues.getIssueIDsAsString())).
|
Where(builder.In("dependency_id", issues.getIssueIDs())).
|
||||||
// sort by repo id then created date, with the issues of the same repo at the beginning of the list
|
// sort by repo id then created date
|
||||||
OrderBy(fmt.Sprintf("CASE WHEN issue.repo_id IN (%s) THEN 0 ELSE issue.repo_id END, issue.created_unix ASC", issues.getRepoIDsAsString())).
|
Asc("issue.repo_id").
|
||||||
|
Asc("issue.created_unix").
|
||||||
Find(&issueDeps)
|
Find(&issueDeps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -642,9 +633,10 @@ func (issues IssueList) BlockedByDependenciesMap(ctx context.Context) (issueDeps
|
||||||
Table("issue").
|
Table("issue").
|
||||||
Join("INNER", "repository", "repository.id = issue.repo_id").
|
Join("INNER", "repository", "repository.id = issue.repo_id").
|
||||||
Join("INNER", "issue_dependency", "issue_dependency.dependency_id = issue.id").
|
Join("INNER", "issue_dependency", "issue_dependency.dependency_id = issue.id").
|
||||||
Where(fmt.Sprintf("issue_id IN (%s)", issues.getIssueIDsAsString())).
|
Where(builder.In("issue_id", issues.getIssueIDs())).
|
||||||
// sort by repo id then created date, with the issues of the same repo at the beginning of the list
|
// sort by repo id then created date
|
||||||
OrderBy(fmt.Sprintf("CASE WHEN issue.repo_id IN (%s) THEN 0 ELSE issue.repo_id END, issue.created_unix ASC", issues.getRepoIDsAsString())).
|
Asc("issue.repo_id").
|
||||||
|
Asc("issue.created_unix").
|
||||||
Find(&issueDeps)
|
Find(&issueDeps)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in New Issue
Block a user