2019-02-19 09:39:39 -05:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2022-11-27 13:20:29 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2019-02-19 09:39:39 -05:00
|
|
|
|
|
|
|
package setting
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
2019-09-11 12:26:28 -05:00
|
|
|
"strings"
|
2019-10-15 08:39:51 -05:00
|
|
|
"time"
|
2019-09-11 12:26:28 -05:00
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
|
|
|
|
"github.com/gobwas/glob"
|
2019-02-19 09:39:39 -05:00
|
|
|
)
|
|
|
|
|
2022-01-20 12:46:10 -05:00
|
|
|
// Indexer settings
|
|
|
|
var Indexer = struct {
|
|
|
|
IssueType string
|
|
|
|
IssuePath string
|
|
|
|
IssueConnStr string
|
|
|
|
IssueIndexerName string
|
|
|
|
StartupTimeout time.Duration
|
|
|
|
|
|
|
|
RepoIndexerEnabled bool
|
|
|
|
RepoType string
|
|
|
|
RepoPath string
|
|
|
|
RepoConnStr string
|
|
|
|
RepoIndexerName string
|
|
|
|
MaxIndexerFileSize int64
|
|
|
|
IncludePatterns []glob.Glob
|
|
|
|
ExcludePatterns []glob.Glob
|
|
|
|
ExcludeVendored bool
|
|
|
|
}{
|
|
|
|
IssueType: "bleve",
|
|
|
|
IssuePath: "indexers/issues.bleve",
|
|
|
|
IssueConnStr: "",
|
|
|
|
IssueIndexerName: "gitea_issues",
|
|
|
|
|
|
|
|
RepoIndexerEnabled: false,
|
|
|
|
RepoType: "bleve",
|
|
|
|
RepoPath: "indexers/repos.bleve",
|
|
|
|
RepoConnStr: "",
|
|
|
|
RepoIndexerName: "gitea_codes",
|
|
|
|
MaxIndexerFileSize: 1024 * 1024,
|
|
|
|
ExcludeVendored: true,
|
|
|
|
}
|
2019-02-19 09:39:39 -05:00
|
|
|
|
2023-02-19 11:12:01 -05:00
|
|
|
func loadIndexerFrom(rootCfg ConfigProvider) {
|
|
|
|
sec := rootCfg.Section("indexer")
|
2019-02-21 00:01:28 -05:00
|
|
|
Indexer.IssueType = sec.Key("ISSUE_INDEXER_TYPE").MustString("bleve")
|
2021-05-25 21:50:35 -05:00
|
|
|
Indexer.IssuePath = filepath.ToSlash(sec.Key("ISSUE_INDEXER_PATH").MustString(filepath.ToSlash(filepath.Join(AppDataPath, "indexers/issues.bleve"))))
|
2019-02-19 09:39:39 -05:00
|
|
|
if !filepath.IsAbs(Indexer.IssuePath) {
|
2021-05-25 21:50:35 -05:00
|
|
|
Indexer.IssuePath = filepath.ToSlash(filepath.Join(AppWorkPath, Indexer.IssuePath))
|
2019-02-19 09:39:39 -05:00
|
|
|
}
|
2020-02-13 01:06:17 -05:00
|
|
|
Indexer.IssueConnStr = sec.Key("ISSUE_INDEXER_CONN_STR").MustString(Indexer.IssueConnStr)
|
|
|
|
Indexer.IssueIndexerName = sec.Key("ISSUE_INDEXER_NAME").MustString(Indexer.IssueIndexerName)
|
|
|
|
|
2021-06-16 17:19:20 -05:00
|
|
|
// The following settings are deprecated and can be overridden by settings in [queue] or [queue.issue_indexer]
|
2022-01-20 12:00:38 -05:00
|
|
|
// FIXME: DEPRECATED to be removed in v1.18.0
|
2023-02-19 11:12:01 -05:00
|
|
|
deprecatedSetting(rootCfg, "indexer", "ISSUE_INDEXER_QUEUE_TYPE", "queue.issue_indexer", "TYPE")
|
|
|
|
deprecatedSetting(rootCfg, "indexer", "ISSUE_INDEXER_QUEUE_DIR", "queue.issue_indexer", "DATADIR")
|
|
|
|
deprecatedSetting(rootCfg, "indexer", "ISSUE_INDEXER_QUEUE_CONN_STR", "queue.issue_indexer", "CONN_STR")
|
|
|
|
deprecatedSetting(rootCfg, "indexer", "ISSUE_INDEXER_QUEUE_BATCH_NUMBER", "queue.issue_indexer", "BATCH_LENGTH")
|
|
|
|
deprecatedSetting(rootCfg, "indexer", "UPDATE_BUFFER_LEN", "queue.issue_indexer", "LENGTH")
|
2020-02-13 01:06:17 -05:00
|
|
|
|
2019-02-19 09:39:39 -05:00
|
|
|
Indexer.RepoIndexerEnabled = sec.Key("REPO_INDEXER_ENABLED").MustBool(false)
|
2020-08-30 11:08:01 -05:00
|
|
|
Indexer.RepoType = sec.Key("REPO_INDEXER_TYPE").MustString("bleve")
|
2021-05-25 21:50:35 -05:00
|
|
|
Indexer.RepoPath = filepath.ToSlash(sec.Key("REPO_INDEXER_PATH").MustString(filepath.ToSlash(filepath.Join(AppDataPath, "indexers/repos.bleve"))))
|
2019-02-19 09:39:39 -05:00
|
|
|
if !filepath.IsAbs(Indexer.RepoPath) {
|
2021-05-25 21:50:35 -05:00
|
|
|
Indexer.RepoPath = filepath.ToSlash(filepath.Join(AppWorkPath, Indexer.RepoPath))
|
2019-02-19 09:39:39 -05:00
|
|
|
}
|
2020-08-30 11:08:01 -05:00
|
|
|
Indexer.RepoConnStr = sec.Key("REPO_INDEXER_CONN_STR").MustString("")
|
|
|
|
Indexer.RepoIndexerName = sec.Key("REPO_INDEXER_NAME").MustString("gitea_codes")
|
|
|
|
|
2019-09-11 12:26:28 -05:00
|
|
|
Indexer.IncludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_INCLUDE").MustString(""))
|
|
|
|
Indexer.ExcludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_EXCLUDE").MustString(""))
|
2020-02-20 14:53:55 -05:00
|
|
|
Indexer.ExcludeVendored = sec.Key("REPO_INDEXER_EXCLUDE_VENDORED").MustBool(true)
|
2019-02-19 09:39:39 -05:00
|
|
|
Indexer.MaxIndexerFileSize = sec.Key("MAX_FILE_SIZE").MustInt64(1024 * 1024)
|
2019-10-15 08:39:51 -05:00
|
|
|
Indexer.StartupTimeout = sec.Key("STARTUP_TIMEOUT").MustDuration(30 * time.Second)
|
2019-02-19 09:39:39 -05:00
|
|
|
}
|
2019-09-11 12:26:28 -05:00
|
|
|
|
|
|
|
// IndexerGlobFromString parses a comma separated list of patterns and returns a glob.Glob slice suited for repo indexing
|
|
|
|
func IndexerGlobFromString(globstr string) []glob.Glob {
|
|
|
|
extarr := make([]glob.Glob, 0, 10)
|
|
|
|
for _, expr := range strings.Split(strings.ToLower(globstr), ",") {
|
|
|
|
expr = strings.TrimSpace(expr)
|
|
|
|
if expr != "" {
|
|
|
|
if g, err := glob.Compile(expr, '.', '/'); err != nil {
|
2021-07-08 06:38:13 -05:00
|
|
|
log.Info("Invalid glob expression '%s' (skipped): %v", expr, err)
|
2019-09-11 12:26:28 -05:00
|
|
|
} else {
|
|
|
|
extarr = append(extarr, g)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return extarr
|
|
|
|
}
|