@@ -21,7 +21,21 @@ type IssueWatchList []*IssueWatch
21
21
22
22
// CreateOrUpdateIssueWatch set watching for a user and issue
23
23
func CreateOrUpdateIssueWatch (userID , issueID int64 , isWatching bool ) error {
24
- iw , exists , err := getIssueWatch (x , userID , issueID )
24
+ sess := x .NewSession ()
25
+ defer sess .Close ()
26
+
27
+ if err := sess .Begin (); err != nil {
28
+ return err
29
+ }
30
+ if err := createOrUpdateIssueWatch (sess , userID , issueID , isWatching ); err != nil {
31
+ return err
32
+ }
33
+
34
+ return sess .Commit ()
35
+ }
36
+
37
+ func createOrUpdateIssueWatch (e Engine , userID , issueID int64 , isWatching bool ) error {
38
+ iw , exists , err := getIssueWatch (e , userID , issueID )
25
39
if err != nil {
26
40
return err
27
41
}
@@ -33,13 +47,13 @@ func CreateOrUpdateIssueWatch(userID, issueID int64, isWatching bool) error {
33
47
IsWatching : isWatching ,
34
48
}
35
49
36
- if _ , err := x .Insert (iw ); err != nil {
50
+ if _ , err := e .Insert (iw ); err != nil {
37
51
return err
38
52
}
39
53
} else {
40
54
iw .IsWatching = isWatching
41
55
42
- if _ , err := x .ID (iw .ID ).Cols ("is_watching" , "updated_unix" ).Update (iw ); err != nil {
56
+ if _ , err := e .ID (iw .ID ).Cols ("is_watching" , "updated_unix" ).Update (iw ); err != nil {
43
57
return err
44
58
}
45
59
}
0 commit comments