@@ -21,7 +21,21 @@ type IssueWatchList []*IssueWatch
2121
2222// CreateOrUpdateIssueWatch set watching for a user and issue
2323func 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 )
2539 if err != nil {
2640 return err
2741 }
@@ -33,13 +47,13 @@ func CreateOrUpdateIssueWatch(userID, issueID int64, isWatching bool) error {
3347 IsWatching : isWatching ,
3448 }
3549
36- if _ , err := x .Insert (iw ); err != nil {
50+ if _ , err := e .Insert (iw ); err != nil {
3751 return err
3852 }
3953 } else {
4054 iw .IsWatching = isWatching
4155
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 {
4357 return err
4458 }
4559 }
0 commit comments