Skip to content

Commit 9178993

Browse files
committed
#2176 fix 500 on /watchers & /stars for pg
1 parent ea375c0 commit 9178993

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

gogs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/gogits/gogs/modules/setting"
1919
)
2020

21-
const APP_VER = "0.8.3.1213"
21+
const APP_VER = "0.8.3.1214"
2222

2323
func init() {
2424
runtime.GOMAXPROCS(runtime.NumCPU())

models/repo.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,8 +1886,13 @@ func GetWatchers(repoID int64) ([]*Watch, error) {
18861886
// Repository.GetWatchers returns range of users watching given repository.
18871887
func (repo *Repository) GetWatchers(page int) ([]*User, error) {
18881888
users := make([]*User, 0, ItemsPerPage)
1889-
return users, x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).
1890-
Where("repo_id=?", repo.ID).Join("LEFT", "watch", "user.id=watch.user_id").Find(&users)
1889+
sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("watch.repo_id=?", repo.ID)
1890+
if setting.UsePostgreSQL {
1891+
sess = sess.Join("LEFT", "watch", `"user".id=watch.user_id`)
1892+
} else {
1893+
sess = sess.Join("LEFT", "watch", "user.id=watch.user_id")
1894+
}
1895+
return users, sess.Find(&users)
18911896
}
18921897

18931898
func notifyWatchers(e Engine, act *Action) error {
@@ -1969,8 +1974,13 @@ func IsStaring(uid, repoId int64) bool {
19691974

19701975
func (repo *Repository) GetStargazers(page int) ([]*User, error) {
19711976
users := make([]*User, 0, ItemsPerPage)
1972-
return users, x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).
1973-
Where("repo_id=?", repo.ID).Join("LEFT", "star", "user.id=star.uid").Find(&users)
1977+
sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("star.repo_id=?", repo.ID)
1978+
if setting.UsePostgreSQL {
1979+
sess = sess.Join("LEFT", "star", `"user".id=star.uid`)
1980+
} else {
1981+
sess = sess.Join("LEFT", "star", "user.id=star.uid")
1982+
}
1983+
return users, sess.Find(&users)
19741984
}
19751985

19761986
// ___________ __

templates/.VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.8.3.1213
1+
0.8.3.1214

0 commit comments

Comments
 (0)