Skip to content

Commit d57a2b9

Browse files
committed
#2743 and #2751 fix bad SQL generated by XORM
Use hand-written SQL to do complex query
1 parent f6759a7 commit d57a2b9

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
33

44
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
55

6-
##### Current version: 0.8.54
6+
##### Current version: 0.8.55
77

88
| Web | UI | Preview |
99
|:-------------:|:-------:|:-------:|

conf/locale/TRANSLATORS

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This file lists all PUBLIC individuals having contributed content to the translation.
1+
# This file lists all PUBLIC individuals having contributed content to the translation.
22
# Entries are in alphabetical order.
33

44
Adam Strzelecki <ono AT java DOT pl>
@@ -36,9 +36,11 @@ Luc Stepniewski <luc AT stepniewski DOT fr>
3636
Luca Kröger <l DOT kroeger01 AT gmail DOT com>
3737
Marc Schiller <marc AT schiller DOT im>
3838
Marvin Menzerath <github AT marvin-menzerath DOT de>
39+
Michael Härtl <haertl DOT mike AT gmail DOT com>
3940
Miguel de la Cruz <miguel AT mcrx DOT me>
4041
Mikhail Burdin <xdshot9000 AT gmail DOT com>
4142
Morten Sørensen <klim8d AT gmail DOT com>
43+
Muhammad Fawwaz Orabi <mfawwaz93 AT gmail DOT com>
4244
Nakao Takamasa <at.mattenn AT gmail DOT com>
4345
Natan Albuquerque <natanalbuquerque5 AT gmail DOT com>
4446
Odilon Junior <odilon DOT junior93 AT gmail DOT com>

gogs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/gogits/gogs/modules/setting"
1818
)
1919

20-
const APP_VER = "0.8.54.0304"
20+
const APP_VER = "0.8.55.0304"
2121

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

models/org.go

+11-15
Original file line numberDiff line numberDiff line change
@@ -1054,11 +1054,10 @@ func RemoveOrgRepo(orgID, repoID int64) error {
10541054
// GetUserRepositories gets all repositories of an organization,
10551055
// that the user with the given userID has access to.
10561056
func (org *User) GetUserRepositories(userID int64) (err error) {
1057-
teams := make([]*Team, 0, 10)
1058-
if err = x.Where("`team_user`.org_id=?", org.Id).
1059-
And("`team_user`.uid=?", userID).
1060-
Join("INNER", "`team_user`", "`team_user`.team_id=`team`.id").
1061-
Find(&teams); err != nil {
1057+
teams := make([]*Team, 0, org.NumTeams)
1058+
if err = x.Sql(`SELECT team.id FROM team
1059+
INNER JOIN team_user ON team_user.team_id = team.id
1060+
WHERE team_user.org_id = ? AND team_user.uid = ?`, org.Id, userID).Find(&teams); err != nil {
10621061
return fmt.Errorf("get teams: %v", err)
10631062
}
10641063

@@ -1071,18 +1070,15 @@ func (org *User) GetUserRepositories(userID int64) (err error) {
10711070
teamIDs = append(teamIDs, "-1") // there is no repo with id=-1
10721071
}
10731072

1074-
// Due to a bug in xorm using IN() together with OR() is impossible.
1075-
// As a workaround, we have to build the IN statement on our own, until this is fixed.
1076-
// https://github.com/go-xorm/xorm/issues/342
1077-
1078-
if err = x.Join("INNER", "`team_repo`", "`team_repo`.repo_id=`repository`.id").
1079-
Where("`repository`.owner_id=?", org.Id).
1080-
And("`repository`.is_private=?", false).
1081-
Or("`team_repo`.team_id IN (?)", strings.Join(teamIDs, ",")).
1082-
GroupBy("`repository`.id").
1083-
Find(&org.Repos); err != nil {
1073+
repos := make([]*Repository, 0, 5)
1074+
if err = x.Sql(`SELECT repository.* FROM repository
1075+
INNER JOIN team_repo ON team_repo.repo_id = repository.id
1076+
WHERE (repository.owner_id = ? AND repository.is_private = ?) OR team_repo.team_id IN (?)
1077+
GROUP BY repository.id`,
1078+
org.Id, false, strings.Join(teamIDs, ",")).Find(&repos); err != nil {
10841079
return fmt.Errorf("get repositories: %v", err)
10851080
}
1081+
org.Repos = repos
10861082

10871083
// FIXME: should I change this value inside method,
10881084
// or only in location of caller where it's really needed?

templates/.VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.8.54.0304
1+
0.8.55.0304

0 commit comments

Comments
 (0)