mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Backport #19244 * remove error who is none * use setupSessionNoLimit instead of setupSessionWithLimit when no pagination Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		@@ -1238,7 +1238,7 @@ func sortIssuesSession(sess *xorm.Session, sortType string, priorityRepoID int64
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
 | 
					func (opts *IssuesOptions) setupSessionWithLimit(sess *xorm.Session) {
 | 
				
			||||||
	if opts.Page >= 0 && opts.PageSize > 0 {
 | 
						if opts.Page >= 0 && opts.PageSize > 0 {
 | 
				
			||||||
		var start int
 | 
							var start int
 | 
				
			||||||
		if opts.Page == 0 {
 | 
							if opts.Page == 0 {
 | 
				
			||||||
@@ -1248,7 +1248,10 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		sess.Limit(opts.PageSize, start)
 | 
							sess.Limit(opts.PageSize, start)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						opts.setupSessionNoLimit(sess)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (opts *IssuesOptions) setupSessionNoLimit(sess *xorm.Session) {
 | 
				
			||||||
	if len(opts.IssueIDs) > 0 {
 | 
						if len(opts.IssueIDs) > 0 {
 | 
				
			||||||
		sess.In("issue.id", opts.IssueIDs)
 | 
							sess.In("issue.id", opts.IssueIDs)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -1414,7 +1417,7 @@ func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	sess := e.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
 | 
						sess := e.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	opts.setupSession(sess)
 | 
						opts.setupSessionNoLimit(sess)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	countsSlice := make([]*struct {
 | 
						countsSlice := make([]*struct {
 | 
				
			||||||
		RepoID int64
 | 
							RepoID int64
 | 
				
			||||||
@@ -1424,7 +1427,7 @@ func CountIssuesByRepo(opts *IssuesOptions) (map[int64]int64, error) {
 | 
				
			|||||||
		Select("issue.repo_id AS repo_id, COUNT(*) AS count").
 | 
							Select("issue.repo_id AS repo_id, COUNT(*) AS count").
 | 
				
			||||||
		Table("issue").
 | 
							Table("issue").
 | 
				
			||||||
		Find(&countsSlice); err != nil {
 | 
							Find(&countsSlice); err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, fmt.Errorf("unable to CountIssuesByRepo: %w", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	countMap := make(map[int64]int64, len(countsSlice))
 | 
						countMap := make(map[int64]int64, len(countsSlice))
 | 
				
			||||||
@@ -1441,14 +1444,14 @@ func GetRepoIDsForIssuesOptions(opts *IssuesOptions, user *user_model.User) ([]i
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	sess := e.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
 | 
						sess := e.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	opts.setupSession(sess)
 | 
						opts.setupSessionNoLimit(sess)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	accessCond := accessibleRepositoryCondition(user)
 | 
						accessCond := accessibleRepositoryCondition(user)
 | 
				
			||||||
	if err := sess.Where(accessCond).
 | 
						if err := sess.Where(accessCond).
 | 
				
			||||||
		Distinct("issue.repo_id").
 | 
							Distinct("issue.repo_id").
 | 
				
			||||||
		Table("issue").
 | 
							Table("issue").
 | 
				
			||||||
		Find(&repoIDs); err != nil {
 | 
							Find(&repoIDs); err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, fmt.Errorf("unable to GetRepoIDsForIssuesOptions: %w", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return repoIDs, nil
 | 
						return repoIDs, nil
 | 
				
			||||||
@@ -1459,17 +1462,16 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
 | 
				
			|||||||
	e := db.GetEngine(db.DefaultContext)
 | 
						e := db.GetEngine(db.DefaultContext)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sess := e.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
 | 
						sess := e.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
 | 
				
			||||||
	opts.setupSession(sess)
 | 
						opts.setupSessionWithLimit(sess)
 | 
				
			||||||
	sortIssuesSession(sess, opts.SortType, opts.PriorityRepoID)
 | 
						sortIssuesSession(sess, opts.SortType, opts.PriorityRepoID)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	issues := make([]*Issue, 0, opts.ListOptions.PageSize)
 | 
						issues := make([]*Issue, 0, opts.ListOptions.PageSize)
 | 
				
			||||||
	if err := sess.Find(&issues); err != nil {
 | 
						if err := sess.Find(&issues); err != nil {
 | 
				
			||||||
		return nil, fmt.Errorf("Find: %v", err)
 | 
							return nil, fmt.Errorf("unable to query Issues: %w", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	sess.Close()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err := IssueList(issues).LoadAttributes(); err != nil {
 | 
						if err := IssueList(issues).LoadAttributes(); err != nil {
 | 
				
			||||||
		return nil, fmt.Errorf("LoadAttributes: %v", err)
 | 
							return nil, fmt.Errorf("unable to LoadAttributes for Issues: %w", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return issues, nil
 | 
						return issues, nil
 | 
				
			||||||
@@ -1480,18 +1482,17 @@ func CountIssues(opts *IssuesOptions) (int64, error) {
 | 
				
			|||||||
	e := db.GetEngine(db.DefaultContext)
 | 
						e := db.GetEngine(db.DefaultContext)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	countsSlice := make([]*struct {
 | 
						countsSlice := make([]*struct {
 | 
				
			||||||
		RepoID int64
 | 
							Count int64
 | 
				
			||||||
		Count  int64
 | 
					 | 
				
			||||||
	}, 0, 1)
 | 
						}, 0, 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sess := e.Select("COUNT(issue.id) AS count").Table("issue")
 | 
						sess := e.Select("COUNT(issue.id) AS count").Table("issue")
 | 
				
			||||||
	sess.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
 | 
						sess.Join("INNER", "repository", "`issue`.repo_id = `repository`.id")
 | 
				
			||||||
	opts.setupSession(sess)
 | 
						opts.setupSessionNoLimit(sess)
 | 
				
			||||||
	if err := sess.Find(&countsSlice); err != nil {
 | 
						if err := sess.Find(&countsSlice); err != nil {
 | 
				
			||||||
		return 0, fmt.Errorf("Find: %v", err)
 | 
							return 0, fmt.Errorf("unable to CountIssues: %w", err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if len(countsSlice) < 1 {
 | 
						if len(countsSlice) != 1 {
 | 
				
			||||||
		return 0, fmt.Errorf("there is less than one result sql record")
 | 
							return 0, fmt.Errorf("unable to get one row result when CountIssues, row count=%d", len(countsSlice))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return countsSlice[0].Count, nil
 | 
						return countsSlice[0].Count, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user