Skip to content

Commit 624cca6

Browse files
committed
fix issues/pr list broken when there are many repositories
1 parent 356e1a7 commit 624cca6

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

models/issue.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,18 +1306,19 @@ func GetIssuesByIDs(issueIDs []int64) ([]*Issue, error) {
13061306

13071307
// IssuesOptions represents options of an issue.
13081308
type IssuesOptions struct {
1309-
RepoIDs []int64 // include all repos if empty
1310-
AssigneeID int64
1311-
PosterID int64
1312-
MentionedID int64
1313-
MilestoneID int64
1314-
Page int
1315-
PageSize int
1316-
IsClosed util.OptionalBool
1317-
IsPull util.OptionalBool
1318-
LabelIDs []int64
1319-
SortType string
1320-
IssueIDs []int64
1309+
RepoIDs []int64 // include all repos if empty
1310+
RepoSubQuery *builder.Builder
1311+
AssigneeID int64
1312+
PosterID int64
1313+
MentionedID int64
1314+
MilestoneID int64
1315+
Page int
1316+
PageSize int
1317+
IsClosed util.OptionalBool
1318+
IsPull util.OptionalBool
1319+
LabelIDs []int64
1320+
SortType string
1321+
IssueIDs []int64
13211322
}
13221323

13231324
// sortIssuesSession sort an issues-related session based on the provided
@@ -1360,7 +1361,9 @@ func (opts *IssuesOptions) setupSession(sess *xorm.Session) {
13601361
sess.In("issue.id", opts.IssueIDs)
13611362
}
13621363

1363-
if len(opts.RepoIDs) > 0 {
1364+
if opts.RepoSubQuery != nil {
1365+
sess.In("issue.repo_id", opts.RepoSubQuery)
1366+
} else if len(opts.RepoIDs) > 0 {
13641367
// In case repository IDs are provided but actually no repository has issue.
13651368
sess.In("issue.repo_id", opts.RepoIDs)
13661369
}

models/user.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,17 @@ func (u *User) GetRepositoryIDs(units ...UnitType) ([]int64, error) {
629629
return ids, sess.Where("owner_id = ?", u.ID).Find(&ids)
630630
}
631631

632+
// UnitRepositoriesSubQuery returns repositories query builder according units
633+
func (u *User) UnitRepositoriesSubQuery(units ...UnitType) *builder.Builder {
634+
b := builder.Select("repository.id").From("repository")
635+
636+
if len(units) > 0 {
637+
b = b.Join("INNER", "repo_unit", "repository.id = repo_unit.repo_id")
638+
b = b.Where(builder.In("repo_unit.type", units))
639+
}
640+
return b.Where(builder.Eq{"owner_id": u.ID})
641+
}
642+
632643
// GetOrgRepositoryIDs returns repositories IDs where user's team owned and has unittypes
633644
func (u *User) GetOrgRepositoryIDs(units ...UnitType) ([]int64, error) {
634645
var ids []int64

routers/user/home.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ func Issues(ctx *context.Context) {
200200
// Get repositories.
201201
var err error
202202
var userRepoIDs []int64
203+
opts := &models.IssuesOptions{
204+
IsClosed: util.OptionalBoolOf(isShowClosed),
205+
IsPull: util.OptionalBoolOf(isPullList),
206+
SortType: sortType,
207+
}
208+
203209
if ctxUser.IsOrganization() {
204210
env, err := ctxUser.AccessibleReposEnv(ctx.User.ID)
205211
if err != nil {
@@ -216,22 +222,12 @@ func Issues(ctx *context.Context) {
216222
if isPullList {
217223
unitType = models.UnitTypePullRequests
218224
}
219-
userRepoIDs, err = ctxUser.GetAccessRepoIDs(unitType)
220-
if err != nil {
221-
ctx.ServerError("ctxUser.GetAccessRepoIDs", err)
222-
return
223-
}
225+
opts.RepoSubQuery = ctxUser.UnitRepositoriesSubQuery(unitType)
224226
}
225227
if len(userRepoIDs) == 0 {
226228
userRepoIDs = []int64{-1}
227229
}
228230

229-
opts := &models.IssuesOptions{
230-
IsClosed: util.OptionalBoolOf(isShowClosed),
231-
IsPull: util.OptionalBoolOf(isPullList),
232-
SortType: sortType,
233-
}
234-
235231
if repoID > 0 {
236232
opts.RepoIDs = []int64{repoID}
237233
}

0 commit comments

Comments
 (0)