From 033d92997fc16baee097d2b25f08e0984e628abd Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Thu, 25 May 2023 04:13:47 -0400 Subject: 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 --- modules/indexer/code/indexer.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'modules/indexer') 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 -- cgit v1.2.3