Skip to content

Commit b461a05

Browse files
committed
fix the number of Repository for Organization on dashboard page
fix #16648 Signed-off-by: a1012112796 <[email protected]>
1 parent d22cb60 commit b461a05

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

models/org.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,35 @@ func queryUserOrgIDs(uid int64) *builder.Builder {
432432
type MinimalOrg = User
433433

434434
// GetUserOrgsList returns one user's all orgs list
435-
func GetUserOrgsList(uid int64) ([]*MinimalOrg, error) {
435+
func GetUserOrgsList(doer *User) ([]*MinimalOrg, error) {
436436
var orgs = make([]*MinimalOrg, 0, 20)
437-
return orgs, x.Select("id, name, full_name, visibility, avatar, avatar_email, use_custom_avatar").
437+
sess := x.NewSession()
438+
defer sess.Close()
439+
440+
err := sess.Select("id, name, full_name, visibility, avatar, avatar_email, use_custom_avatar").
438441
Table("user").
439-
In("id", queryUserOrgIDs(uid)).
442+
In("id", queryUserOrgIDs(doer.ID)).
440443
Find(&orgs)
444+
445+
if err != nil {
446+
return nil, err
447+
}
448+
449+
for _, org := range orgs {
450+
cond := SearchRepositoryCondition(&SearchRepoOptions{
451+
Actor: doer,
452+
Private: true,
453+
OwnerID: org.ID,
454+
AllPublic: false, // Include also all public repositories of users and public organisations
455+
AllLimited: false, // Include also all public repositories of limited organisations
456+
})
457+
org.NumRepos, err = countRepositoryByCondition(x, cond)
458+
if err != nil {
459+
return nil, err
460+
}
461+
}
462+
463+
return orgs, nil
441464
}
442465

443466
func getOwnedOrgsByUserID(sess *xorm.Session, userID int64) ([]*User, error) {

models/repo_list.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,13 @@ func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
366366
return SearchRepositoryByCondition(opts, cond, true)
367367
}
368368

369+
func countRepositoryByCondition(e Engine, cond builder.Cond) (int, error) {
370+
count, err := e.
371+
Where(cond).
372+
Count(new(Repository))
373+
return int(count), err
374+
}
375+
369376
// SearchRepositoryByCondition search repositories by condition
370377
func SearchRepositoryByCondition(opts *SearchRepoOptions, cond builder.Cond, loadAttributes bool) (RepositoryList, int64, error) {
371378
sess, count, err := searchRepositoryByCondition(opts, cond)

routers/web/user/home.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ func getDashboardContextUser(ctx *context.Context) *models.User {
4949
}
5050
ctx.Data["ContextUser"] = ctxUser
5151

52-
orgs, err := models.GetUserOrgsList(ctx.User.ID)
52+
orgs, err := models.GetUserOrgsList(ctx.User)
5353
if err != nil {
5454
ctx.ServerError("GetUserOrgsList", err)
5555
return nil
5656
}
57+
5758
ctx.Data["Orgs"] = orgs
5859

5960
return ctxUser

0 commit comments

Comments
 (0)