diff --git a/models/repo.go b/models/repo.go index 2b9fc0d9e..8d16371ed 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1072,14 +1072,14 @@ func CountUserRepositories(userID int64, private bool) int64 { return countRepositories(userID, private) } -func Repositories(page, pageSize int) (_ []*Repository, err error) { +func Repositories(page, pageSize int, _ int64) (_ []*Repository, err error) { repos := make([]*Repository, 0, pageSize) return repos, x.Limit(pageSize, (page-1)*pageSize).Asc("id").Find(&repos) } // RepositoriesWithUsers returns number of repos in given page. func RepositoriesWithUsers(page, pageSize int) (_ []*Repository, err error) { - repos, err := Repositories(page, pageSize) + repos, err := Repositories(page, pageSize, -1) if err != nil { return nil, fmt.Errorf("Repositories: %v", err) } @@ -1553,9 +1553,18 @@ func GetUserMirrorRepositories(userID int64) ([]*Repository, error) { } // GetRecentUpdatedRepositories returns the list of repositories that are recently updated. -func GetRecentUpdatedRepositories(page, pageSize int) (repos []*Repository, err error) { - return repos, x.Limit(pageSize, (page-1)*pageSize). - Where("is_private=?", false).Limit(pageSize).Desc("updated_unix").Find(&repos) +func GetRecentUpdatedRepositories(page, pageSize int, userID int64) (repos []*Repository, err error) { + repos, _, err = SearchRepositoryByName(&SearchRepoOptions{ + Keyword: "%", + UserID: userID, + OrderBy: "updated_unix DESC", + Private: false, + Page: page, + PageSize: pageSize, + }) + return repos, err + //return repos, x.Limit(pageSize, (page-1)*pageSize). + // Where("is_private=?", false).Limit(pageSize).Desc("updated_unix").Find(&repos) } func getRepositoryCount(e Engine, u *User) (int64, error) { diff --git a/routers/home.go b/routers/home.go index 3c1aa6d59..0767be94a 100644 --- a/routers/home.go +++ b/routers/home.go @@ -47,7 +47,7 @@ func Home(ctx *context.Context) { type RepoSearchOptions struct { Counter func(bool) int64 - Ranger func(int, int) ([]*models.Repository, error) + Ranger func(int, int, int64) ([]*models.Repository, error) Private bool PageSize int OrderBy string @@ -59,6 +59,10 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { if page <= 0 { page = 1 } + var ctxUserID int64 + if ctx.IsSigned { + ctxUserID = ctx.User.ID + } var ( repos []*models.Repository @@ -68,17 +72,13 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { keyword := ctx.Query("q") if len(keyword) == 0 { - repos, err = opts.Ranger(page, opts.PageSize) + repos, err = opts.Ranger(page, opts.PageSize, ctxUserID) if err != nil { ctx.Handle(500, "opts.Ranger", err) return } count = opts.Counter(opts.Private) } else { - var ctxUserID int64 - if ctx.IsSigned { - ctxUserID = ctx.User.ID - } repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{ Keyword: keyword, UserID: ctxUserID,