Browse Source

#2743 and #2751 fix bad SQL generated by XORM

Use hand-written SQL to do complex query
tags/v1.2.0-rc1
Unknwon 9 years ago
parent
commit
7989af0eba
5 changed files with 17 additions and 19 deletions
  1. +1
    -1
      README.md
  2. +3
    -1
      conf/locale/TRANSLATORS
  3. +1
    -1
      gogs.go
  4. +11
    -15
      models/org.go
  5. +1
    -1
      templates/.VERSION

+ 1
- 1
README.md View File

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


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


##### Current version: 0.8.54
##### Current version: 0.8.55


| Web | UI | Preview | | Web | UI | Preview |
|:-------------:|:-------:|:-------:| |:-------------:|:-------:|:-------:|


+ 3
- 1
conf/locale/TRANSLATORS View File

@@ -1,4 +1,4 @@
# This file lists all PUBLIC individuals having contributed content to the translation.
# This file lists all PUBLIC individuals having contributed content to the translation.
# Entries are in alphabetical order. # Entries are in alphabetical order.


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


+ 1
- 1
gogs.go View File

@@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )


const APP_VER = "0.8.54.0304"
const APP_VER = "0.8.55.0304"


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


+ 11
- 15
models/org.go View File

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


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


// Due to a bug in xorm using IN() together with OR() is impossible.
// As a workaround, we have to build the IN statement on our own, until this is fixed.
// https://github.com/go-xorm/xorm/issues/342

if err = x.Join("INNER", "`team_repo`", "`team_repo`.repo_id=`repository`.id").
Where("`repository`.owner_id=?", org.Id).
And("`repository`.is_private=?", false).
Or("`team_repo`.team_id IN (?)", strings.Join(teamIDs, ",")).
GroupBy("`repository`.id").
Find(&org.Repos); err != nil {
repos := make([]*Repository, 0, 5)
if err = x.Sql(`SELECT repository.* FROM repository
INNER JOIN team_repo ON team_repo.repo_id = repository.id
WHERE (repository.owner_id = ? AND repository.is_private = ?) OR team_repo.team_id IN (?)
GROUP BY repository.id`,
org.Id, false, strings.Join(teamIDs, ",")).Find(&repos); err != nil {
return fmt.Errorf("get repositories: %v", err) return fmt.Errorf("get repositories: %v", err)
} }
org.Repos = repos


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


+ 1
- 1
templates/.VERSION View File

@@ -1 +1 @@
0.8.54.0304
0.8.55.0304

Loading…
Cancel
Save