-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
base: main
Are you sure you want to change the base?
Conversation
// 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"], |
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.
this make it easyer to match human keywords with api options ... but if prefered I could also use the const directly ...
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.
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 ...........
I would say this refactor is ready ;) |
I will review and merge after v1.22 stable is released since it's a refactor PR. |
@lunny we now have v1.22.0 tagged :) |
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.
(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 { |
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 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" |
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.
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.
@delvh that are two valid refactors :) But as this is already taking that long i propose to make two small followup pulls adressing it :) |
The first one is a bug, not a refactor. |
// Strings for sorting result | ||
const ( | ||
// only used for repos | ||
SearchOrderByAlphabetically db.SearchOrderBy = "owner_name ASC, name ASC" |
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.
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.
have repo OrderBy definitions defined in one place and use a single type for OrderBy database options