mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-30 03:14:29 +01:00 
			
		
		
		
	Simplify the code to get issue count (#19380)
* Simple the code to get issue count * Improve codes
This commit is contained in:
		
							parent
							
								
									2ec2baf248
								
							
						
					
					
						commit
						fc002860d8
					
				| @ -1510,20 +1510,10 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) { | |||||||
| func CountIssues(opts *IssuesOptions) (int64, error) { | func CountIssues(opts *IssuesOptions) (int64, error) { | ||||||
| 	e := db.GetEngine(db.DefaultContext) | 	e := db.GetEngine(db.DefaultContext) | ||||||
| 
 | 
 | ||||||
| 	countsSlice := make([]*struct { |  | ||||||
| 		Count int64 |  | ||||||
| 	}, 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.setupSessionNoLimit(sess) | 	opts.setupSessionNoLimit(sess) | ||||||
| 	if err := sess.Find(&countsSlice); err != nil { | 	return sess.Count() | ||||||
| 		return 0, fmt.Errorf("unable to CountIssues: %w", err) |  | ||||||
| 	} |  | ||||||
| 	if len(countsSlice) != 1 { |  | ||||||
| 		return 0, fmt.Errorf("unable to get one row result when CountIssues, row count=%d", len(countsSlice)) |  | ||||||
| 	} |  | ||||||
| 	return countsSlice[0].Count, nil |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // GetParticipantsIDsByIssueID returns the IDs of all users who participated in comments of an issue, | // GetParticipantsIDsByIssueID returns the IDs of all users who participated in comments of an issue, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user