mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Rewrite delivery of issue and comment mails (#9009)
* Mail issue subscribers, rework the function * Simplify a little more * Fix unused variable * Refactor mail delivery to avoid heavy load on server * Avoid splitting into too many goroutines * Fix comments and optimize GetMaileableUsersByIDs() * Fix return on errors
This commit is contained in:
		@@ -1219,6 +1219,19 @@ func Issues(opts *IssuesOptions) ([]*Issue, error) {
 | 
			
		||||
	return issues, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetParticipantsIDsByIssueID returns the IDs of all users who participated in comments of an issue,
 | 
			
		||||
// but skips joining with `user` for performance reasons.
 | 
			
		||||
// User permissions must be verified elsewhere if required.
 | 
			
		||||
func GetParticipantsIDsByIssueID(issueID int64) ([]int64, error) {
 | 
			
		||||
	userIDs := make([]int64, 0, 5)
 | 
			
		||||
	return userIDs, x.Table("comment").
 | 
			
		||||
		Cols("poster_id").
 | 
			
		||||
		Where("issue_id = ?", issueID).
 | 
			
		||||
		And("type in (?,?,?)", CommentTypeComment, CommentTypeCode, CommentTypeReview).
 | 
			
		||||
		Distinct("poster_id").
 | 
			
		||||
		Find(&userIDs)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetParticipantsByIssueID returns all users who are participated in comments of an issue.
 | 
			
		||||
func GetParticipantsByIssueID(issueID int64) ([]*User, error) {
 | 
			
		||||
	return getParticipantsByIssueID(x, issueID)
 | 
			
		||||
 
 | 
			
		||||
@@ -41,6 +41,18 @@ func (issue *Issue) loadAssignees(e Engine) (err error) {
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetAssigneeIDsByIssue returns the IDs of users assigned to an issue
 | 
			
		||||
// but skips joining with `user` for performance reasons.
 | 
			
		||||
// User permissions must be verified elsewhere if required.
 | 
			
		||||
func GetAssigneeIDsByIssue(issueID int64) ([]int64, error) {
 | 
			
		||||
	userIDs := make([]int64, 0, 5)
 | 
			
		||||
	return userIDs, x.Table("issue_assignees").
 | 
			
		||||
		Cols("assignee_id").
 | 
			
		||||
		Where("issue_id = ?", issueID).
 | 
			
		||||
		Distinct("assignee_id").
 | 
			
		||||
		Find(&userIDs)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetAssigneesByIssue returns everyone assigned to that issue
 | 
			
		||||
func GetAssigneesByIssue(issue *Issue) (assignees []*User, err error) {
 | 
			
		||||
	return getAssigneesByIssue(x, issue)
 | 
			
		||||
 
 | 
			
		||||
@@ -60,6 +60,18 @@ func getIssueWatch(e Engine, userID, issueID int64) (iw *IssueWatch, exists bool
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetIssueWatchersIDs returns IDs of subscribers to a given issue id
 | 
			
		||||
// but avoids joining with `user` for performance reasons
 | 
			
		||||
// User permissions must be verified elsewhere if required
 | 
			
		||||
func GetIssueWatchersIDs(issueID int64) ([]int64, error) {
 | 
			
		||||
	ids := make([]int64, 0, 64)
 | 
			
		||||
	return ids, x.Table("issue_watch").
 | 
			
		||||
		Where("issue_id=?", issueID).
 | 
			
		||||
		And("is_watching = ?", true).
 | 
			
		||||
		Select("user_id").
 | 
			
		||||
		Find(&ids)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetIssueWatchers returns watchers/unwatchers of a given issue
 | 
			
		||||
func GetIssueWatchers(issueID int64) (IssueWatchList, error) {
 | 
			
		||||
	return getIssueWatchers(x, issueID)
 | 
			
		||||
 
 | 
			
		||||
@@ -140,6 +140,18 @@ func GetWatchers(repoID int64) ([]*Watch, error) {
 | 
			
		||||
	return getWatchers(x, repoID)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetRepoWatchersIDs returns IDs of watchers for a given repo ID
 | 
			
		||||
// but avoids joining with `user` for performance reasons
 | 
			
		||||
// User permissions must be verified elsewhere if required
 | 
			
		||||
func GetRepoWatchersIDs(repoID int64) ([]int64, error) {
 | 
			
		||||
	ids := make([]int64, 0, 64)
 | 
			
		||||
	return ids, x.Table("watch").
 | 
			
		||||
		Where("watch.repo_id=?", repoID).
 | 
			
		||||
		And("watch.mode<>?", RepoWatchModeDont).
 | 
			
		||||
		Select("user_id").
 | 
			
		||||
		Find(&ids)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetWatchers returns range of users watching given repository.
 | 
			
		||||
func (repo *Repository) GetWatchers(page int) ([]*User, error) {
 | 
			
		||||
	users := make([]*User, 0, ItemsPerPage)
 | 
			
		||||
 
 | 
			
		||||
@@ -1307,6 +1307,20 @@ func getUserEmailsByNames(e Engine, names []string) []string {
 | 
			
		||||
	return mails
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetMaileableUsersByIDs gets users from ids, but only if they can receive mails
 | 
			
		||||
func GetMaileableUsersByIDs(ids []int64) ([]*User, error) {
 | 
			
		||||
	if len(ids) == 0 {
 | 
			
		||||
		return nil, nil
 | 
			
		||||
	}
 | 
			
		||||
	ous := make([]*User, 0, len(ids))
 | 
			
		||||
	return ous, x.In("id", ids).
 | 
			
		||||
		Where("`type` = ?", UserTypeIndividual).
 | 
			
		||||
		And("`prohibit_login` = ?", false).
 | 
			
		||||
		And("`is_active` = ?", true).
 | 
			
		||||
		And("`email_notifications_preference` = ?", EmailNotificationsEnabled).
 | 
			
		||||
		Find(&ous)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetUsersByIDs returns all resolved users from a list of Ids.
 | 
			
		||||
func GetUsersByIDs(ids []int64) ([]*User, error) {
 | 
			
		||||
	ous := make([]*User, 0, len(ids))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user