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

In code search, get code unit accessible repos in one (main) query #19764

Merged
merged 12 commits into from
Jun 15, 2022
Merged

In code search, get code unit accessible repos in one (main) query #19764

merged 12 commits into from
Jun 15, 2022

Conversation

hoitih
Copy link
Contributor

@hoitih hoitih commented May 19, 2022

Fix for #12849.

The slow search that non-Admin users experienced was in my opinion not caused by the fact that some queries were slow, but a lot of querying was done each time the 'explore/code' page was rendered or the 'search' was actually performed.
So in file routers/explore/web/code.go I added a check if a keyword to search for was present, otherwise the logic for searching is skipped. That fixed slow rendering of an empty page 'explore/code'.
When actually performing a search, first a list is created with Repository ID's where the user has access to (when the user is not an Admin or Guest user). That took quite a lot of time: first a list was retrieved using a db-query in method FindUserAccessibleRepoIDs() to which a user has general access, followed by logic to check for each repository if the user has access at Code level. This check for each repository leads to a lot of queries in case of a lot of repositories.

Since method FindUserAccessibleRepoIDs() was only used on the explore/code page, I changed it's name to FindUserCodeAccessibleRepoIDs() logic to return only repository ID's the user has access to at Code level and deleted the code in file routers/explore/web/code.go that checked this.

To make FindUserCodeAccessibleRepoIDs() only return repository ID's the user has access to at Code level, I changed generic method accessibleRepositoryCondition(user) to accept a second argument unit.Type. In this method I made sure it worked in the same way as before if an unit.TypeInvalid was passed as argument. In all other places this method was used I specified this unit.TypeInvalid. Only within method FindUserCodeAccessibleRepoIDs() I passed unit.TypeCode as second argument to accessibleRepositoryCondition(). Since only 'general' access to a repository is registered in db-table access, a query to this table cannot be used if looking for access given at the level of a specific unit.Type. That kind of access is registered in db-table team_unit. I added 'joins' for that in de db WHERE-condition. Since the level of Access to a unit.Type can be 'None' I added a check for this too, to making sure it is at least 'Read'. Furthermore I added a condition for adding repository ID's where the user is (external) collaborator in.

Tested for Admin and non-Admin users with Elastic as Code Indexer.
In development mode with SQLite on Windows10/WSL2 with go 1.17.7.

In bindata mode in a docker container (build with the provided Dockerfile) and with PostgreSQL as database.

@Gusted Gusted added this to the 1.17.0 milestone May 22, 2022
@Gusted Gusted added the performance/speed performance issues with slow downs label May 22, 2022
@zeripath
Copy link
Contributor

Heya!

Thanks for the PR.

I think it would be helpful if you updated your PR description to describe your changes and the reasoning behind them. I'm not saying you've done it wrong here - just that we need to get better at describing how your PR actually works and improves things.

This section of code is complex and difficult to review.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 24, 2022
@hoitih
Copy link
Contributor Author

hoitih commented May 24, 2022

Hello there!

Update the PR description.

models/issue.go Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

Codecov Report

Merging #19764 (9be48b3) into main (ad551bf) will decrease coverage by 0.08%.
The diff coverage is 25.84%.

@@            Coverage Diff             @@
##             main   #19764      +/-   ##
==========================================
- Coverage   47.40%   47.31%   -0.09%     
==========================================
  Files         958      957       -1     
  Lines      133604   133334     -270     
==========================================
- Hits        63331    63084     -247     
+ Misses      62612    62583      -29     
- Partials     7661     7667       +6     
Impacted Files Coverage Δ
routers/web/explore/code.go 0.00% <0.00%> (ø)
models/lfs.go 21.93% <50.00%> (ø)
models/repo_list.go 80.25% <60.60%> (-2.15%) ⬇️
models/issue.go 54.18% <100.00%> (-0.25%) ⬇️
models/org.go 62.99% <100.00%> (ø)
models/repo/user_repo.go 0.00% <0.00%> (-26.67%) ⬇️
models/db/context.go 70.10% <0.00%> (-14.90%) ⬇️
modules/queue/queue_channel.go 76.85% <0.00%> (-4.63%) ⬇️
models/organization/org_user.go 92.53% <0.00%> (-4.61%) ⬇️
models/repo/repo_indexer.go 47.69% <0.00%> (-3.74%) ⬇️
... and 85 more

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 ad551bf...9be48b3. Read the comment docs.

Copy link
Contributor

@zeripath zeripath left a comment

Choose a reason for hiding this comment

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

I wonder if it would be helpful to add an alias for unit.TypeInvalid unit.TypeAny that we could use instead for these search conditions.

(I'm not sure about this though but it would look a bit better..)

models/repo_list.go Outdated Show resolved Hide resolved
models/repo_list.go Outdated Show resolved Hide resolved
@zeripath
Copy link
Contributor

I was meaning that you should put the description of what the PR is doing from (#19764 (comment)) into the opening comment of the PR.

@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 2, 2022
@lunny
Copy link
Member

lunny commented Jun 10, 2022

Please resolve the conflicts.

@hoitih
Copy link
Contributor Author

hoitih commented Jun 14, 2022

Please resolve the conflicts.

Done

@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 15, 2022
@lafriks lafriks merged commit 6473bd3 into go-gitea:main Jun 15, 2022
zjjhot added a commit to zjjhot/gitea that referenced this pull request Jun 16, 2022
* giteaofficial/main:
  Allow render HTML with css/js external links (go-gitea#19017)
  Use correct count for `NumOpenIssues` (go-gitea#19980)
  In code search, get code unit accessible repos in one (main) query (go-gitea#19764)
  [skip ci] Updated translations via Crowdin
  Always try to fetch repo for mirrors (go-gitea#19975)
  Remove tab/TabName usage where it's not needed (go-gitea#19973)
  Fix cli command restore-repo: "units" should be parsed as StringSlice (go-gitea#19953)
  Uppercase first languages letters (go-gitea#19965)
  Move tests as seperate sub packages to reduce duplicated file names (go-gitea#19951)
  Replace unstyled meter with progress (go-gitea#19968)
  [skip ci] Updated translations via Crowdin
  [skip ci] Updated translations via Crowdin
  Remove singuliere from MAINTAINERS (go-gitea#19883)
  Fix aria for logo (go-gitea#19955)
  Fix mirror template bug (go-gitea#19959)
vsysoev pushed a commit to IntegraSDL/gitea that referenced this pull request Aug 10, 2022
…o-gitea#19764)

* When non-admin users use code search, get code unit accessible repos in one main query

* Modified some comments to match the changes

* Removed unnecessary check for Access Mode in Collaboration table

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Lauris BH <lauris@nix.lv>
AbdulrhmnGhanem pushed a commit to kitspace/gitea that referenced this pull request Aug 24, 2022
…o-gitea#19764)

* When non-admin users use code search, get code unit accessible repos in one main query

* Modified some comments to match the changes

* Removed unnecessary check for Access Mode in Collaboration table

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Lauris BH <lauris@nix.lv>
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
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. performance/speed performance issues with slow downs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants