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

Add a way to opt out of repo code indexing, on a per-repo basis #20418

Closed
wants to merge 1 commit into from
Closed

Add a way to opt out of repo code indexing, on a per-repo basis #20418

wants to merge 1 commit into from

Conversation

algernon
Copy link
Contributor

@algernon algernon commented Jul 20, 2022

Add a repository setting to opt out of code indexing. When the indexer iterates over repositories, if it sees a repo with the setting disabled, it will remove that repository from the index, otherwise it continues.

The new setting is on by default, and is exposed in the repository settings page, in the advanced settings box, right alongside the Projects and Packages enabling checkboxes.

Addresses #17824, albeit in a different way.

Screenshot

Screenshot from 2022-07-23 06-49-43

@codecov-commenter
Copy link

Codecov Report

Merging #20418 (4c9b50e) into main (fee0e4d) will increase coverage by 0.00%.
The diff coverage is 14.51%.

@@           Coverage Diff           @@
##             main   #20418   +/-   ##
=======================================
  Coverage   46.88%   46.88%           
=======================================
  Files         976      976           
  Lines      135193   135248   +55     
=======================================
+ Hits        63384    63413   +29     
- Misses      64040    64066   +26     
  Partials     7769     7769           
Impacted Files Coverage Δ
cmd/admin.go 0.00% <0.00%> (ø)
models/issues/review.go 52.77% <0.00%> (-1.31%) ⬇️
models/repo/repo.go 62.61% <ø> (ø)
routers/web/org/members.go 0.00% <0.00%> (ø)
routers/web/repo/pull_review.go 0.00% <0.00%> (ø)
routers/web/repo/setting.go 16.61% <0.00%> (-0.31%) ⬇️
services/forms/repo_form.go 40.76% <ø> (ø)
services/pull/review.go 48.24% <7.14%> (-2.58%) ⬇️
modules/indexer/code/indexer.go 32.15% <100.00%> (+0.90%) ⬆️
modules/repository/create.go 43.35% <100.00%> (+0.32%) ⬆️
... and 9 more

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jul 20, 2022
Add a repository setting to opt out of code indexing. When the indexer iterates
over repositories, if it sees a repo with the setting disabled, it will remove
that repository from the index, otherwise it continues.

The new setting is on by default, and is exposed in the repository settings
page, in the advanced settings box, right alongside the Projects and Packages
enabling checkboxes.

Addresses #17824, albeit in a different way.

Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
@algernon algernon changed the title [WIP] Add a way to opt out of repo code indexing, on a per-repo basis Add a way to opt out of repo code indexing, on a per-repo basis Jul 23, 2022
@algernon algernon marked this pull request as ready for review July 23, 2022 04:54
@algernon
Copy link
Contributor Author

I turned the setting into something accessible for all repo owners, rather than limiting it to admins. The only part I'm unsure about is where toggling the option on or off and updating the settings, code.UpdateRepoIndexer() is triggered. That's something another option hidden behind an admin-only flag does too, so perhaps it would make more sense to not call it here, and just have the next indexer run - whenever it happens - take care of updating things. However, that has the downside of the change potentially taking a long time to take effect.

@lafriks
Copy link
Member

lafriks commented Jul 23, 2022

I would say that changing option should trigger repository reindex as it may not happen ever if repository is not changed

@Gusted Gusted added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Aug 1, 2022
@@ -158,6 +158,7 @@ type Repository struct {
CodeIndexerStatus *RepoIndexerStatus `xorm:"-"`
StatsIndexerStatus *RepoIndexerStatus `xorm:"-"`
IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"`
IsCodeIndexingEnabled bool `xorm:"NOT NULL DEFAULT true"`
Copy link
Contributor

Choose a reason for hiding this comment

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

This require a migration, it should be similar to models/migrations/v219.go, copy paste this whole struct(fixup the imports) and run Sync2 on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!

May take a day or two until I have some cycles to spend on updating this PR, but I'll get there eventually.

@Gusted Gusted added this to the 1.18.0 milestone Aug 1, 2022
Comment on lines +427 to +428
<input class="enable-system" name="enable_code_indexing" type="checkbox" {{if .Repository.IsCodeIndexingEnabled}}checked{{end}}>
<label>{{.locale.Tr "repo.settings.code_search_indexing_desc"}}</label>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<input class="enable-system" name="enable_code_indexing" type="checkbox" {{if .Repository.IsCodeIndexingEnabled}}checked{{end}}>
<label>{{.locale.Tr "repo.settings.code_search_indexing_desc"}}</label>
<input type="checkbox" class="enable-system" id="code-indexing-checkbox" name="enable_code_indexing"{{if .Repository.IsCodeIndexingEnabled}} checked{{end}}>
<label for="code-indexing-checkbox">{{.locale.Tr "repo.settings.code_search_indexing_desc"}}</label>

Comment on lines +398 to +401
if repo.IsCodeIndexingEnabled != form.EnableCodeIndexing {
repo.IsCodeIndexingEnabled = form.EnableCodeIndexing
codeIndexingChanged = true
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if repo.IsCodeIndexingEnabled != form.EnableCodeIndexing {
repo.IsCodeIndexingEnabled = form.EnableCodeIndexing
codeIndexingChanged = true
}
codeIndexingChanged = repo.IsCodeIndexingEnabled != form.EnableCodeIndexing
if codeIndexingChanged {
repo.IsCodeIndexingEnabled = form.EnableCodeIndexing
}

@lunny lunny modified the milestones: 1.18.0, 1.19.0 Oct 19, 2022
@algernon algernon closed this by deleting the head repository Oct 27, 2022
@lunny lunny removed this from the 1.19.0 milestone Feb 22, 2023
@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/need 2 This PR needs two approvals by maintainers to be considered for merging. type/feature Completely new functionality. Can only be merged if feature freeze is not active.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants