mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	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
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user