2019-02-19 14:39:39 +00:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package setting
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
2019-09-11 17:26:28 +00:00
|
|
|
"strings"
|
2019-10-15 13:39:51 +00:00
|
|
|
"time"
|
2019-09-11 17:26:28 +00:00
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/log"
|
|
|
|
|
|
|
|
"github.com/gobwas/glob"
|
2019-02-19 14:39:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// enumerates all the indexer queue types
|
|
|
|
const (
|
|
|
|
LevelQueueType = "levelqueue"
|
|
|
|
ChannelQueueType = "channel"
|
2019-04-08 09:05:15 +00:00
|
|
|
RedisQueueType = "redis"
|
2019-02-19 14:39:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// Indexer settings
|
|
|
|
Indexer = struct {
|
2019-04-08 09:05:15 +00:00
|
|
|
IssueType string
|
|
|
|
IssuePath string
|
2020-02-13 06:06:17 +00:00
|
|
|
IssueConnStr string
|
|
|
|
IssueIndexerName string
|
2019-04-08 09:05:15 +00:00
|
|
|
IssueQueueType string
|
|
|
|
IssueQueueDir string
|
|
|
|
IssueQueueConnStr string
|
|
|
|
IssueQueueBatchNumber int
|
2019-10-15 13:39:51 +00:00
|
|
|
StartupTimeout time.Duration
|
2020-02-13 06:06:17 +00:00
|
|
|
|
|
|
|
RepoIndexerEnabled bool
|
2020-08-30 16:08:01 +00:00
|
|
|
RepoType string
|
2020-02-13 06:06:17 +00:00
|
|
|
RepoPath string
|
2020-08-30 16:08:01 +00:00
|
|
|
RepoConnStr string
|
|
|
|
RepoIndexerName string
|
2020-02-13 06:06:17 +00:00
|
|
|
UpdateQueueLength int
|
|
|
|
MaxIndexerFileSize int64
|
|
|
|
IncludePatterns []glob.Glob
|
|
|
|
ExcludePatterns []glob.Glob
|
2020-02-20 19:53:55 +00:00
|
|
|
ExcludeVendored bool
|
2019-02-19 14:39:39 +00:00
|
|
|
}{
|
2019-04-08 09:05:15 +00:00
|
|
|
IssueType: "bleve",
|
|
|
|
IssuePath: "indexers/issues.bleve",
|
2020-02-13 06:06:17 +00:00
|
|
|
IssueConnStr: "",
|
|
|
|
IssueIndexerName: "gitea_issues",
|
2019-04-08 09:05:15 +00:00
|
|
|
IssueQueueType: LevelQueueType,
|
|
|
|
IssueQueueDir: "indexers/issues.queue",
|
|
|
|
IssueQueueConnStr: "",
|
|
|
|
IssueQueueBatchNumber: 20,
|
2019-12-23 12:31:16 +00:00
|
|
|
|
2020-08-30 16:08:01 +00:00
|
|
|
RepoIndexerEnabled: false,
|
|
|
|
RepoType: "bleve",
|
|
|
|
RepoPath: "indexers/repos.bleve",
|
|
|
|
RepoConnStr: "",
|
|
|
|
RepoIndexerName: "gitea_codes",
|
2019-12-23 12:31:16 +00:00
|
|
|
MaxIndexerFileSize: 1024 * 1024,
|
2020-02-20 19:53:55 +00:00
|
|
|
ExcludeVendored: true,
|
2019-02-19 14:39:39 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func newIndexerService() {
|
|
|
|
sec := Cfg.Section("indexer")
|
2019-02-21 05:01:28 +00:00
|
|
|
Indexer.IssueType = sec.Key("ISSUE_INDEXER_TYPE").MustString("bleve")
|
2019-02-19 14:39:39 +00:00
|
|
|
Indexer.IssuePath = sec.Key("ISSUE_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/issues.bleve"))
|
|
|
|
if !filepath.IsAbs(Indexer.IssuePath) {
|
|
|
|
Indexer.IssuePath = path.Join(AppWorkPath, Indexer.IssuePath)
|
|
|
|
}
|
2020-02-13 06:06:17 +00:00
|
|
|
Indexer.IssueConnStr = sec.Key("ISSUE_INDEXER_CONN_STR").MustString(Indexer.IssueConnStr)
|
|
|
|
Indexer.IssueIndexerName = sec.Key("ISSUE_INDEXER_NAME").MustString(Indexer.IssueIndexerName)
|
|
|
|
|
|
|
|
Indexer.IssueQueueType = sec.Key("ISSUE_INDEXER_QUEUE_TYPE").MustString(LevelQueueType)
|
|
|
|
Indexer.IssueQueueDir = sec.Key("ISSUE_INDEXER_QUEUE_DIR").MustString(path.Join(AppDataPath, "indexers/issues.queue"))
|
2020-10-07 22:24:41 +00:00
|
|
|
Indexer.IssueQueueConnStr = sec.Key("ISSUE_INDEXER_QUEUE_CONN_STR").MustString("")
|
2020-02-13 06:06:17 +00:00
|
|
|
Indexer.IssueQueueBatchNumber = sec.Key("ISSUE_INDEXER_QUEUE_BATCH_NUMBER").MustInt(20)
|
|
|
|
|
2019-02-19 14:39:39 +00:00
|
|
|
Indexer.RepoIndexerEnabled = sec.Key("REPO_INDEXER_ENABLED").MustBool(false)
|
2020-08-30 16:08:01 +00:00
|
|
|
Indexer.RepoType = sec.Key("REPO_INDEXER_TYPE").MustString("bleve")
|
2019-02-19 14:39:39 +00:00
|
|
|
Indexer.RepoPath = sec.Key("REPO_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/repos.bleve"))
|
|
|
|
if !filepath.IsAbs(Indexer.RepoPath) {
|
|
|
|
Indexer.RepoPath = path.Join(AppWorkPath, Indexer.RepoPath)
|
|
|
|
}
|
2020-08-30 16:08:01 +00:00
|
|
|
Indexer.RepoConnStr = sec.Key("REPO_INDEXER_CONN_STR").MustString("")
|
|
|
|
Indexer.RepoIndexerName = sec.Key("REPO_INDEXER_NAME").MustString("gitea_codes")
|
|
|
|
|
2019-09-11 17:26:28 +00:00
|
|
|
Indexer.IncludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_INCLUDE").MustString(""))
|
|
|
|
Indexer.ExcludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_EXCLUDE").MustString(""))
|
2020-02-20 19:53:55 +00:00
|
|
|
Indexer.ExcludeVendored = sec.Key("REPO_INDEXER_EXCLUDE_VENDORED").MustBool(true)
|
2019-02-19 14:39:39 +00:00
|
|
|
Indexer.UpdateQueueLength = sec.Key("UPDATE_BUFFER_LEN").MustInt(20)
|
|
|
|
Indexer.MaxIndexerFileSize = sec.Key("MAX_FILE_SIZE").MustInt64(1024 * 1024)
|
2019-10-15 13:39:51 +00:00
|
|
|
Indexer.StartupTimeout = sec.Key("STARTUP_TIMEOUT").MustDuration(30 * time.Second)
|
2019-02-19 14:39:39 +00:00
|
|
|
}
|
2019-09-11 17:26:28 +00: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 {
|
|
|
|
log.Info("Invalid glob expresion '%s' (skipped): %v", expr, err)
|
|
|
|
} else {
|
|
|
|
extarr = append(extarr, g)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return extarr
|
|
|
|
}
|