diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-20 16:14:50 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-20 16:14:50 -0400 |
commit | 53a17bbd240e0dd3755b7a666792d69e358f3e00 (patch) | |
tree | 2b48d4e8f562730f288053c9ef90445a07426f47 /models | |
parent | 06631ab91f5d84b48d6f71ac8eaf4df740ba0282 (diff) | |
download | gitea-53a17bbd240e0dd3755b7a666792d69e358f3e00.tar.gz gitea-53a17bbd240e0dd3755b7a666792d69e358f3e00.zip |
Bug fix
Diffstat (limited to 'models')
-rw-r--r-- | models/repo.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/models/repo.go b/models/repo.go index f7173d76d0..f5ceaf7631 100644 --- a/models/repo.go +++ b/models/repo.go @@ -424,9 +424,18 @@ type Watch struct { // Watch or unwatch repository. func WatchRepo(userId, repoId int64, watch bool) (err error) { if watch { - _, err = orm.Insert(&Watch{RepoId: repoId, UserId: userId}) + if _, err = orm.Insert(&Watch{RepoId: repoId, UserId: userId}); err != nil { + return err + } + + rawSql := "UPDATE `repository` SET num_watches = num_watches + 1 WHERE id = ?" + _, err = orm.Exec(rawSql, repoId) } else { - _, err = orm.Delete(&Watch{0, repoId, userId}) + if _, err = orm.Delete(&Watch{0, repoId, userId}); err != nil { + return err + } + rawSql := "UPDATE `repository` SET num_watches = num_watches - 1 WHERE id = ?" + _, err = orm.Exec(rawSql, repoId) } return err } |