Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination on releases page #2035

Merged
merged 10 commits into from
Jun 28, 2017
9 changes: 9 additions & 0 deletions models/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ func GetReleasesByRepoID(repoID int64, page, pageSize int) (rels []*Release, err
return rels, err
}

// GetReleaseCountByRepoID returns the count of releases of repository
func GetReleaseCountByRepoID(repoID int64, isOwner bool) (total int64, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I think a variable name like includeDrafts would be more clear than isOwner.
  2. Are return variable names necessary here? They don't seem to ever be used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just (int64, error) would be better

if isOwner {
return x.Where("repo_id = ?", repoID).Count(&Release{})
}

return x.Where("repo_id = ? AND is_prerelease = 0 AND is_draft = 0", repoID).Count(&Release{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should use a Cond struct instead of a string, similar to this and then you can pass it to Where method

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this probably wont work in postgres as I think xorm creates bool columns in it.

}

// GetReleasesByRepoIDAndNames returns a list of releases of repository according repoID and tagNames.
func GetReleasesByRepoIDAndNames(repoID int64, tagNames []string) (rels []*Release, err error) {
err = x.
Expand Down
8 changes: 7 additions & 1 deletion routers/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ func Releases(ctx *context.Context) {
return
}

count, err := models.GetReleaseCountByRepoID(ctx.Repo.Repository.ID, ctx.Repo.IsOwner())
if err != nil {
ctx.Handle(500, "GetReleaseCountByRepoID", err)
return
}

err = models.GetReleaseAttachments(releases...)
if err != nil {
ctx.Handle(500, "GetReleaseAttachments", err)
Expand Down Expand Up @@ -110,7 +116,7 @@ func Releases(ctx *context.Context) {
releasesToDisplay = append(releasesToDisplay, r)
}

pager := paginater.New(len(releasesToDisplay), limit, page, 5)
pager := paginater.New(int(count), limit, page, 5)
ctx.Data["Page"] = pager
ctx.Data["Releases"] = releasesToDisplay
ctx.HTML(200, tplReleases)
Expand Down