0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-17 23:41:49 +01:00

optimization on database IN

This commit is contained in:
Lunny Xiao 2016-11-12 01:31:37 +08:00
parent 9bf28a2799
commit ade6d4a20f

View file

@ -10,9 +10,8 @@ import (
"os" "os"
"strings" "strings"
"github.com/go-xorm/builder"
"github.com/go-xorm/xorm" "github.com/go-xorm/xorm"
"code.gitea.io/gitea/modules/base"
) )
var ( var (
@ -540,7 +539,7 @@ func (org *User) GetUserRepositories(userID int64, page, pageSize int) ([]*Repos
Select("`repository`.*"). Select("`repository`.*").
Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id"). Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id").
Where("(`repository`.owner_id=? AND `repository`.is_private=?)", org.ID, false). Where("(`repository`.owner_id=? AND `repository`.is_private=?)", org.ID, false).
Or("team_repo.team_id IN (?)", strings.Join(base.Int64sToStrings(teamIDs), ",")). Or(builder.In("team_repo.team_id", teamIDs)).
GroupBy("`repository`.id"). GroupBy("`repository`.id").
OrderBy("updated_unix DESC"). OrderBy("updated_unix DESC").
Limit(pageSize, (page-1)*pageSize). Limit(pageSize, (page-1)*pageSize).
@ -551,7 +550,7 @@ func (org *User) GetUserRepositories(userID int64, page, pageSize int) ([]*Repos
repoCount, err := x. repoCount, err := x.
Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id"). Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id").
Where("(`repository`.owner_id=? AND `repository`.is_private=?)", org.ID, false). Where("(`repository`.owner_id=? AND `repository`.is_private=?)", org.ID, false).
Or("team_repo.team_id IN (?)", strings.Join(base.Int64sToStrings(teamIDs), ",")). Or(builder.In("team_repo.team_id", teamIDs)).
GroupBy("`repository`.id"). GroupBy("`repository`.id").
Count(&Repository{}) Count(&Repository{})
if err != nil { if err != nil {
@ -577,7 +576,7 @@ func (org *User) GetUserMirrorRepositories(userID int64) ([]*Repository, error)
Select("`repository`.*"). Select("`repository`.*").
Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id AND `repository`.is_mirror=?", true). Join("INNER", "team_repo", "`team_repo`.repo_id=`repository`.id AND `repository`.is_mirror=?", true).
Where("(`repository`.owner_id=? AND `repository`.is_private=?)", org.ID, false). Where("(`repository`.owner_id=? AND `repository`.is_private=?)", org.ID, false).
Or("team_repo.team_id IN (?)", strings.Join(base.Int64sToStrings(teamIDs), ",")). Or(builder.In("team_repo.team_id", teamIDs)).
GroupBy("`repository`.id"). GroupBy("`repository`.id").
OrderBy("updated_unix DESC"). OrderBy("updated_unix DESC").
Find(&repos) Find(&repos)