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
Merged

Pagination on releases page #2035

merged 10 commits into from
Jun 28, 2017

Conversation

iszla
Copy link
Contributor

@iszla iszla commented Jun 22, 2017

Reason for why the pagination did not work, was because the paginater was never given a higher count than the amount of releases to display (which is max 10)
Added GetReleaseCountByRepoID function to get count of releases so pagination will work on releases page.
Count also checks if user is owner, so if there are many prereleases and/or drafts the page count should not be off.

Tested by being logged in as owner, and not logged in.

Fixes #1863

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 22, 2017
Copy link
Member

@lafriks lafriks left a comment

Choose a reason for hiding this comment

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

It will not work correctly anyway as GetReleasesByRepoID will return all releases not depending by condition (draft + owner). If not owner will be looking at release page he will get (limit - draft releases) in first page

@iszla
Copy link
Contributor Author

iszla commented Jun 22, 2017

That is true, and something that I noticed, so if you have 10 draft releases the first page will be empty. Difference here is that you will be able to go to page two by clicking to see releases instead of just seeing an empty screen. Also trying to understand why the tests are failing

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.

@iszla
Copy link
Contributor Author

iszla commented Jun 22, 2017

Switched to cond struct, and also removed checking if it was a prerelease as this seemed to be incorrect since you can see prereleases even if you are not the owner, as long as they are not drafts

@@ -244,6 +245,19 @@ 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

@@ -67,7 +67,13 @@ func Releases(ctx *context.Context) {

releases, err := models.GetReleasesByRepoID(ctx.Repo.Repository.ID, page, limit)
Copy link
Member

@ethantkoenig ethantkoenig Jun 22, 2017

Choose a reason for hiding this comment

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

We should also make sure that if we're not the owner, then this doesn't return drafts. I know that we check in the for loop below, but right now it's possible that we end up displaying fewer than limit releases on the first page, even if there are more than limit displayable releases in total.

EDIT: Oh, looks like @lafriks already pointed this out 😂

Copy link
Member

@ethantkoenig ethantkoenig left a comment

Choose a reason for hiding this comment

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

One more thing

return x.Where(cond).Count(&Release{})
}

cond = cond.And(builder.Eq{"is_draft": 0})
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be false instead of 0.

}

return x.Where("repo_id = ? AND is_prerelease = 0 AND is_draft = 0", repoID).Count(&Release{})
cond = cond.And(builder.Eq{"is_draft": 0})
Copy link
Member

Choose a reason for hiding this comment

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

It must be false instead of 0

@lunny lunny added this to the 1.2.0 milestone Jun 23, 2017
@lunny lunny added the type/bug label Jun 23, 2017
@Bwko
Copy link
Member

Bwko commented Jun 27, 2017

LGTM

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Jun 27, 2017
@lunny
Copy link
Member

lunny commented Jun 28, 2017

@iszla need force push to let CI work.

@lafriks
Copy link
Member

lafriks commented Jun 28, 2017

LGTM I will fix GetReleasesByRepoID in other PR so #1863 can't be closed just yet

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 28, 2017
@lafriks
Copy link
Member

lafriks commented Jun 28, 2017

@ethantkoenig need your approval

@ethantkoenig
Copy link
Member

ethantkoenig commented Jun 28, 2017

@lafriks Okay, as long as GetReleasesByRepoID eventually gets fixed I'll approve

@lafriks
Copy link
Member

lafriks commented Jun 28, 2017

@ethantkoenig thats on my task list for today when I get home ;)

@lunny lunny merged commit 3f90164 into go-gitea:master Jun 28, 2017
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Release page don't paginate
7 participants