From f2ae3bdc0163a8e3c48fa89b981985eff6e020e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Niclas=20Oelschl=C3=A4ger?= Date: Thu, 15 Feb 2024 21:22:09 +0100 Subject: [PATCH] refactor: use xorm builder --- models/issues/issue_list.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/models/issues/issue_list.go b/models/issues/issue_list.go index 9e6172f920..5684d3a398 100644 --- a/models/issues/issue_list.go +++ b/models/issues/issue_list.go @@ -6,7 +6,6 @@ package issues import ( "context" "fmt" - "strings" "code.gitea.io/gitea/models/db" project_model "code.gitea.io/gitea/models/project" @@ -34,11 +33,6 @@ func (issues IssueList) getRepoIDs() []int64 { 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 func (issues IssueList) LoadRepositories(ctx context.Context) (repo_model.RepositoryList, error) { if len(issues) == 0 { @@ -145,10 +139,6 @@ func (issues IssueList) getIssueIDs() []int64 { 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 { if len(issues) == 0 { return nil @@ -617,9 +607,10 @@ func (issues IssueList) BlockingDependenciesMap(ctx context.Context) (issueDepsM Table("issue"). Join("INNER", "repository", "repository.id = issue.repo_id"). Join("INNER", "issue_dependency", "issue_dependency.issue_id = issue.id"). - Where(fmt.Sprintf("dependency_id IN (%s)", issues.getIssueIDsAsString())). - // sort by repo id then created date, with the issues of the same repo at the beginning of the list - OrderBy(fmt.Sprintf("CASE WHEN issue.repo_id IN (%s) THEN 0 ELSE issue.repo_id END, issue.created_unix ASC", issues.getRepoIDsAsString())). + Where(builder.In("dependency_id", issues.getIssueIDs())). + // sort by repo id then created date + Asc("issue.repo_id"). + Asc("issue.created_unix"). Find(&issueDeps) if err != nil { return nil, err @@ -642,9 +633,10 @@ func (issues IssueList) BlockedByDependenciesMap(ctx context.Context) (issueDeps Table("issue"). Join("INNER", "repository", "repository.id = issue.repo_id"). Join("INNER", "issue_dependency", "issue_dependency.dependency_id = issue.id"). - Where(fmt.Sprintf("issue_id IN (%s)", issues.getIssueIDsAsString())). - // sort by repo id then created date, with the issues of the same repo at the beginning of the list - OrderBy(fmt.Sprintf("CASE WHEN issue.repo_id IN (%s) THEN 0 ELSE issue.repo_id END, issue.created_unix ASC", issues.getRepoIDsAsString())). + Where(builder.In("issue_id", issues.getIssueIDs())). + // sort by repo id then created date + Asc("issue.repo_id"). + Asc("issue.created_unix"). Find(&issueDeps) if err != nil { return nil, err