Skip to content

Commit 0c5c34d

Browse files
authored
UpdateIssueUsersByMentions was calling database write operations while (#443)
a transaction session was in progress. MailParticipants was failing silently because of the SQLITE_LOCKED error. Make sure failures in MailParticipants enter the log, and pass on the transaction context. issue: let caller pass in database context, and use it issue_comment: obtain database context to pass to UpdateIssueMentions issue_comment: log any error from call to MailParticipants issue_mail: pass on database context to UpdateIssueMentions
1 parent 4c89a9c commit 0c5c34d

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

models/issue.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ func GetIssueUserPairsByMode(uid, rid int64, isClosed bool, page, filterMode int
10851085

10861086
// UpdateIssueMentions extracts mentioned people from content and
10871087
// updates issue-user relations for them.
1088-
func UpdateIssueMentions(issueID int64, mentions []string) error {
1088+
func UpdateIssueMentions(e Engine, issueID int64, mentions []string) error {
10891089
if len(mentions) == 0 {
10901090
return nil
10911091
}
@@ -1095,7 +1095,7 @@ func UpdateIssueMentions(issueID int64, mentions []string) error {
10951095
}
10961096
users := make([]*User, 0, len(mentions))
10971097

1098-
if err := x.In("lower_name", mentions).Asc("lower_name").Find(&users); err != nil {
1098+
if err := e.In("lower_name", mentions).Asc("lower_name").Find(&users); err != nil {
10991099
return fmt.Errorf("find mentioned users: %v", err)
11001100
}
11011101

@@ -1119,7 +1119,7 @@ func UpdateIssueMentions(issueID int64, mentions []string) error {
11191119
ids = append(ids, memberIDs...)
11201120
}
11211121

1122-
if err := UpdateIssueUsersByMentions(issueID, ids); err != nil {
1122+
if err := UpdateIssueUsersByMentions(e, issueID, ids); err != nil {
11231123
return fmt.Errorf("UpdateIssueUsersByMentions: %v", err)
11241124
}
11251125

@@ -1361,22 +1361,22 @@ func UpdateIssueUserByRead(uid, issueID int64) error {
13611361
}
13621362

13631363
// UpdateIssueUsersByMentions updates issue-user pairs by mentioning.
1364-
func UpdateIssueUsersByMentions(issueID int64, uids []int64) error {
1364+
func UpdateIssueUsersByMentions(e Engine, issueID int64, uids []int64) error {
13651365
for _, uid := range uids {
13661366
iu := &IssueUser{
13671367
UID: uid,
13681368
IssueID: issueID,
13691369
}
1370-
has, err := x.Get(iu)
1370+
has, err := e.Get(iu)
13711371
if err != nil {
13721372
return err
13731373
}
13741374

13751375
iu.IsMentioned = true
13761376
if has {
1377-
_, err = x.Id(iu.ID).AllCols().Update(iu)
1377+
_, err = e.Id(iu.ID).AllCols().Update(iu)
13781378
} else {
1379-
_, err = x.Insert(iu)
1379+
_, err = e.Insert(iu)
13801380
}
13811381
if err != nil {
13821382
return err

models/issue_comment.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ func (c *Comment) EventTag() string {
187187

188188
// MailParticipants sends new comment emails to repository watchers
189189
// and mentioned people.
190-
func (c *Comment) MailParticipants(opType ActionType, issue *Issue) (err error) {
190+
func (c *Comment) MailParticipants(e Engine, opType ActionType, issue *Issue) (err error) {
191191
mentions := markdown.FindAllMentions(c.Content)
192-
if err = UpdateIssueMentions(c.IssueID, mentions); err != nil {
192+
if err = UpdateIssueMentions(e, c.IssueID, mentions); err != nil {
193193
return fmt.Errorf("UpdateIssueMentions [%d]: %v", c.IssueID, err)
194194
}
195195

@@ -303,7 +303,9 @@ func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err
303303
if err = notifyWatchers(e, act); err != nil {
304304
log.Error(4, "notifyWatchers: %v", err)
305305
}
306-
comment.MailParticipants(act.OpType, opts.Issue)
306+
if err = comment.MailParticipants(e, act.OpType, opts.Issue); err != nil {
307+
log.Error(4, "MailParticipants: %v", err)
308+
}
307309
}
308310

309311
return comment, nil

models/issue_mail.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string)
6969
// and mentioned people.
7070
func (issue *Issue) MailParticipants() (err error) {
7171
mentions := markdown.FindAllMentions(issue.Content)
72-
if err = UpdateIssueMentions(issue.ID, mentions); err != nil {
72+
if err = UpdateIssueMentions(x, issue.ID, mentions); err != nil {
7373
return fmt.Errorf("UpdateIssueMentions [%d]: %v", issue.ID, err)
7474
}
7575

0 commit comments

Comments
 (0)