Skip to content

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

Merged

Conversation

Morlinest
Copy link
Member

@Morlinest Morlinest commented Oct 4, 2017

Remove useless functions/code. Fixes multiple bugs and remove duplicated code, like:

  • Corrects ordering of repositories on admin page
  • Corrects results when searching (explore page) - now you can get 2 different results when searching with/without keyword because two different functions are used and implementation is not same for both. But results with non empty keyword should always contains subset of full search (empty keyword) results.
  • models.Repositories() ignores privacy settings in search but uses it for count (even it's always true as it is used only in 1 place with fixed privacy settings). This function can be replaced by models.SearchRepositoryByName() as it does exactly same thing.
  • models.GetRecentUpdatedRepositories() doesn't make sense, as it is used only if query parameter q 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.

@codecov-io
Copy link

codecov-io commented Oct 4, 2017

Codecov Report

Merging #2652 into master will increase coverage by 0.1%.
The diff coverage is 70%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
models/issue_indexer.go 8.21% <0%> (-0.24%) ⬇️
models/repo_list.go 53.12% <100%> (+17.41%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c2346e4...d3e349b. Read the comment docs.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 4, 2017
@Morlinest Morlinest force-pushed the fix/use-same-function-for-repo-search branch from 3576ce4 to 195d7f1 Compare October 4, 2017 13:49
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.

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,
Copy link
Member

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?

Copy link
Member Author

@Morlinest Morlinest Oct 4, 2017

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.

Copy link
Member Author

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,
Copy link
Member

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,?

Copy link
Member Author

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.

@@ -129,6 +129,8 @@ const (
SearchOrderByNewest = "created_unix DESC"
SearchOrderBySize = "size ASC"
SearchOrderBySizeReverse = "size DESC"
SearchOrderByID = "ID ASC"
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@Morlinest Morlinest force-pushed the fix/use-same-function-for-repo-search branch 3 times, most recently from 75100dd to 782d9ab Compare October 4, 2017 18:12
@Morlinest
Copy link
Member Author

@ethantkoenig This is how it looks now:

image
image

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, ...

@lafriks lafriks added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Oct 5, 2017
@lafriks lafriks added this to the 1.3.0 milestone Oct 5, 2017
@daviian
Copy link
Member

daviian commented Oct 7, 2017

@Morlinest Tested and seems good to me except one point: I miss owned private repositories in explore page (for none-admins).

@daviian
Copy link
Member

daviian commented Oct 7, 2017

@Morlinest Please rebase :)

@Morlinest
Copy link
Member Author

@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)).

@daviian
Copy link
Member

daviian commented Oct 8, 2017

@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.

@Morlinest
Copy link
Member Author

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.

@Morlinest Morlinest force-pushed the fix/use-same-function-for-repo-search branch from 054f9ba to 8d999c8 Compare October 8, 2017 09:38
@muellert
Copy link

muellert commented Oct 8, 2017

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.

@lafriks
Copy link
Member

lafriks commented Oct 8, 2017

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

@Morlinest
Copy link
Member Author

OK, I'll change current behaviour.

@muellert
Copy link

muellert commented Oct 8, 2017

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?

@Morlinest Morlinest force-pushed the fix/use-same-function-for-repo-search branch from 4cb10e8 to 2c85a19 Compare October 9, 2017 08:53
@Morlinest
Copy link
Member Author

@daviian @lafriks Behaviour changed. Explore page now show always all public repositories and private repositories available to logged user. I had to add new option to models.SearchRepoOptions.

@Morlinest Morlinest force-pushed the fix/use-same-function-for-repo-search branch from 2c85a19 to 6d47b19 Compare October 9, 2017 14:24
@Morlinest Morlinest force-pushed the fix/use-same-function-for-repo-search branch from 6d47b19 to 4a32cbe Compare October 10, 2017 01:47
@@ -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})
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 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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@Morlinest Morlinest force-pushed the fix/use-same-function-for-repo-search branch from 4a32cbe to ceb8174 Compare October 10, 2017 04:14
@ethantkoenig
Copy link
Member

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 Oct 10, 2017
@Morlinest
Copy link
Member Author

Added unit tests.

@daviian
Copy link
Member

daviian commented Oct 10, 2017

LGTM

@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 Oct 10, 2017
@bkcsoft bkcsoft merged commit dff26e2 into go-gitea:master Oct 10, 2017
@Morlinest Morlinest deleted the fix/use-same-function-for-repo-search branch October 10, 2017 20:42
@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/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.

8 participants