-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Conversation
There was a problem hiding this 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
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 |
models/release.go
Outdated
return x.Where("repo_id = ?", repoID).Count(&Release{}) | ||
} | ||
|
||
return x.Where("repo_id = ? AND is_prerelease = 0 AND is_draft = 0", repoID).Count(&Release{}) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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 |
models/release.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I think a variable name like
includeDrafts
would be more clear thanisOwner
. - Are return variable names necessary here? They don't seem to ever be used.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing
models/release.go
Outdated
return x.Where(cond).Count(&Release{}) | ||
} | ||
|
||
cond = cond.And(builder.Eq{"is_draft": 0}) |
There was a problem hiding this comment.
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
.
models/release.go
Outdated
} | ||
|
||
return x.Where("repo_id = ? AND is_prerelease = 0 AND is_draft = 0", repoID).Count(&Release{}) | ||
cond = cond.And(builder.Eq{"is_draft": 0}) |
There was a problem hiding this comment.
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
LGTM |
@iszla need force push to let CI work. |
LGTM I will fix |
@ethantkoenig need your approval |
@lafriks Okay, as long as |
@ethantkoenig thats on my task list for today when I get home ;) |
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