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

[Refactor] Unify repo search order by logic #30876

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

6543
Copy link
Member

@6543 6543 commented May 6, 2024

have repo OrderBy definitions defined in one place and use a single type for OrderBy database options

@6543 6543 added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label May 6, 2024
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 6, 2024
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 6, 2024
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label May 6, 2024
// SearchOrderByFlatMap is similar to SearchOrderByMap but use human language keywords
// to decide between asc and desc
var SearchOrderByFlatMap = map[string]db.SearchOrderBy{
"newest": SearchOrderByMap["desc"]["created"],
Copy link
Member Author

Choose a reason for hiding this comment

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

this make it easyer to match human keywords with api options ... but if prefered I could also use the const directly ...

Copy link
Contributor

Choose a reason for hiding this comment

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

but if prefered I could also use the const directly ...

I also prefer. No need to introduce a one-time const or one-time variable ...........

models/repo/search.go Outdated Show resolved Hide resolved
@github-actions github-actions bot added the modifies/api This PR adds API routes or modifies them label May 6, 2024
@6543
Copy link
Member Author

6543 commented May 7, 2024

I would say this refactor is ready ;)

@6543 6543 requested a review from lunny May 7, 2024 12:16
@lunny
Copy link
Member

lunny commented May 7, 2024

I would say this refactor is ready ;)

I will review and merge after v1.22 stable is released since it's a refactor PR.

6543 added a commit that referenced this pull request May 7, 2024
similar to #30784 but only for the repo explore page

is covered by #30876 for the main branch
@6543 6543 added this to the 1.23.0 milestone May 7, 2024
@6543
Copy link
Member Author

6543 commented Jun 10, 2024

@lunny we now have v1.22.0 tagged :)

@GiteaBot GiteaBot 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 12, 2024
Copy link
Member

@delvh delvh left a comment

Choose a reason for hiding this comment

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

(LGTM although we should probably fix the uppercase problem before the merge)

orderBy = db.SearchOrderByForks
default:
ctx.Data["SortType"] = "recentupdate"
if order, ok := repo_model.SearchOrderByFlatMap[sortOrder]; ok {
Copy link
Member

@delvh delvh Jun 12, 2024

Choose a reason for hiding this comment

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

One potential problem with this approach:
ASc or ASC results in the default sorting, even if a valid sorting is given
We should probably lowercase the order first

// Strings for sorting result
const (
// only used for repos
SearchOrderByAlphabetically db.SearchOrderBy = "owner_name ASC, name ASC"
Copy link
Member

Choose a reason for hiding this comment

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

If it wasn't already present in the original code, I'd propose dropping the Search- prefix in this PR.
It only confuses without bringing any additional value.
As it exists already, I'll see that I open another refactoring PR once this one was merged.

@GiteaBot GiteaBot 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 12, 2024
@6543
Copy link
Member Author

6543 commented Jun 12, 2024

@delvh that are two valid refactors :)

But as this is already taking that long i propose to make two small followup pulls adressing it :)

@delvh
Copy link
Member

delvh commented Jun 12, 2024

The first one is a bug, not a refactor.
And the bug is introduced through this PR:
You query the sorting using a potentially unsanitized value, so you need to sanitize (lowercase) it first beforehand

// Strings for sorting result
const (
// only used for repos
SearchOrderByAlphabetically db.SearchOrderBy = "owner_name ASC, name ASC"
Copy link
Contributor

Choose a reason for hiding this comment

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

Every const here is only used once for constructing the "map"

I think all of these const should be removed, and just fill the values into the map directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants