]> source.dussan.org Git - gitea.git/commitdiff
Bug fix
authorUnknown <joe2010xtmf@163.com>
Thu, 20 Mar 2014 20:14:50 +0000 (16:14 -0400)
committerUnknown <joe2010xtmf@163.com>
Thu, 20 Mar 2014 20:14:50 +0000 (16:14 -0400)
models/repo.go

index f7173d76d033f6239c22cb06eee54e638307c01b..f5ceaf7631f29b4b2af5eafff55ae779286b390f 100644 (file)
@@ -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
 }