summaryrefslogtreecommitdiffstats
path: root/modules/indexer
diff options
context:
space:
mode:
authortechknowlogick <techknowlogick@gitea.io>2023-05-25 04:13:47 -0400
committerGitHub <noreply@github.com>2023-05-25 16:13:47 +0800
commit033d92997fc16baee097d2b25f08e0984e628abd (patch)
tree731c2ed48759bbb86baeb837c7da8a06078a03a3 /modules/indexer
parentcff4e37d43595d0ad22b634c274d62b04ab9a468 (diff)
downloadgitea-033d92997fc16baee097d2b25f08e0984e628abd.tar.gz
gitea-033d92997fc16baee097d2b25f08e0984e628abd.zip
Allow skipping forks and mirrors from being indexed (#23187)
This PR adds two new options to disable repo/code search indexing of both forks and mirrors. Related: #22842
Diffstat (limited to 'modules/indexer')
-rw-r--r--modules/indexer/code/indexer.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/modules/indexer/code/indexer.go b/modules/indexer/code/indexer.go
index a5e40b52c1..e9b8e76500 100644
--- a/modules/indexer/code/indexer.go
+++ b/modules/indexer/code/indexer.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/modules/queue"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
+ "code.gitea.io/gitea/modules/util"
)
// SearchResult result of performing a search in a repo
@@ -91,6 +92,32 @@ func index(ctx context.Context, indexer Indexer, repoID int64) error {
return err
}
+ repoTypes := setting.Indexer.RepoIndexerRepoTypes
+
+ if len(repoTypes) == 0 {
+ repoTypes = []string{"sources"}
+ }
+
+ // skip forks from being indexed if unit is not present
+ if !util.SliceContains(repoTypes, "forks") && repo.IsFork {
+ return nil
+ }
+
+ // skip mirrors from being indexed if unit is not present
+ if !util.SliceContains(repoTypes, "mirrors") && repo.IsMirror {
+ return nil
+ }
+
+ // skip templates from being indexed if unit is not present
+ if !util.SliceContains(repoTypes, "templates") && repo.IsTemplate {
+ return nil
+ }
+
+ // skip regular repos from being indexed if unit is not present
+ if !util.SliceContains(repoTypes, "sources") && !repo.IsFork && !repo.IsMirror && !repo.IsTemplate {
+ return nil
+ }
+
sha, err := getDefaultBranchSha(ctx, repo)
if err != nil {
return err