-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Remove redudant functions and code #2652
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
Remove redudant functions and code #2652
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2652 +/- ##
=========================================
+ Coverage 27.28% 27.38% +0.1%
=========================================
Files 86 86
Lines 17062 17010 -52
=========================================
+ Hits 4655 4658 +3
+ Misses 11728 11673 -55
Partials 679 679
Continue to review full report at Codecov.
|
3576ce4
to
195d7f1
Compare
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 seems that the RepoSearchOptions.Searcher
field is never used. I think we still need to use it, but if not then we should just remove the field.
routers/home.go
Outdated
PageSize: setting.UI.ExplorePagingNum, | ||
Searcher: ctx.User, |
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.
Why is this line removed?
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.
Not needed anymore. But now I see I have to make some changes as models.GetRecentUpdatedRepositories()
need only Searcher
and not OwnerID
.
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.
@ethantkoenig I looked at it again and I don't need to change anything. Reason is to unify behaviour when you search with/without keyword. I'll post images.
routers/home.go
Outdated
PageSize: opts.PageSize, | ||
OrderBy: orderBy, | ||
Private: opts.Private, | ||
Keyword: keyword, |
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.
Should we add Searcher: opts.Searcher,
?
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.
Searcher
is useless without OwnerID
. In models.SearchRepositoryByName
is used only if OwnerID > 0
.
models/repo_list.go
Outdated
@@ -129,6 +129,8 @@ const ( | |||
SearchOrderByNewest = "created_unix DESC" | |||
SearchOrderBySize = "size ASC" | |||
SearchOrderBySizeReverse = "size DESC" | |||
SearchOrderByID = "ID 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.
Please write column names lowercase
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.
Done
75100dd
to
782d9ab
Compare
@ethantkoenig This is how it looks now: This PR should fix that. Explore page should be only for showing public repositories (as it is if you use any keyword). For private there is dashboard, user page, user settings, ... |
@Morlinest Tested and seems good to me except one point: I miss owned private repositories in explore page (for none-admins). |
@Morlinest Please rebase :) |
@daviian Yes, it's expected change. The reason is explained in second and last point in PR description. Try to open explore page on current master build and type any keyword, you will be missing private repositories (example screenshots: #2652 (comment)). |
@Morlinest But instead of removing it for all results, it should be included IMO. But I think I am ok if we fix that in another PR. |
I am not against it, but it would be few more changes to code. If also @lafriks or @ethantkoenig (or any other member :)) agree with it, I can change it to show private repositories (owned + collaborative) of signed user too. |
054f9ba
to
8d999c8
Compare
I am very new to Gitea and have no Gogs experience, so my thinking may not be in line with the philosophy of the software at all, but I think item visibility should only depend on the role of the user performing a search and on the ACL for that item, not on which page the user started the search on. |
I also think that user should see on explore page all repositories he has access. For example in my company all repositories are private and in such case that would totally make that page useless |
OK, I'll change current behaviour. |
I wrote "items" because I don't know if repos are the only type of things affected. But I'd like to be able to find other things like issues or wiki pages as well, if I generally have access to them. Where would I look in the code to figure all of this out? |
4cb10e8
to
2c85a19
Compare
2c85a19
to
6d47b19
Compare
6d47b19
to
4a32cbe
Compare
@@ -182,6 +185,10 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, coun | |||
cond = cond.And(builder.Eq{"is_private": false}) | |||
} | |||
|
|||
if opts.OwnerID > 0 && opts.AllPublic { | |||
cond = cond.Or(builder.Eq{"is_private": false}) |
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 is a bug. If opts.OwnerID > 0 && opts.AllPublic
is true, then we will search for all public repos, even those that do not match the keyword.
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.
Fixed
4a32cbe
to
ceb8174
Compare
LGTM |
Added unit tests. |
LGTM |
Remove useless functions/code. Fixes multiple bugs and remove duplicated code, like:
models.Repositories()
ignores privacy settings in search but uses it forcount
(even it's always true as it is used only in 1 place with fixed privacy settings). This function can be replaced bymodels.SearchRepositoryByName()
as it does exactly same thing.models.GetRecentUpdatedRepositories()
doesn't make sense, as it is used only if query parameterq
is empty and can return results with different ordering (not "recent updated").models.SearchRepositoryByName()
should do same thing.Bonus: less code to maintain, less space for bugs :)
Extracted from #2371 and further improved.