You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
4.0 KiB

  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package setting
  5. import (
  6. "path"
  7. "path/filepath"
  8. "strings"
  9. "time"
  10. "code.gitea.io/gitea/modules/log"
  11. "github.com/gobwas/glob"
  12. )
  13. // enumerates all the indexer queue types
  14. const (
  15. LevelQueueType = "levelqueue"
  16. ChannelQueueType = "channel"
  17. RedisQueueType = "redis"
  18. )
  19. var (
  20. // Indexer settings
  21. Indexer = struct {
  22. IssueType string
  23. IssuePath string
  24. IssueConnStr string
  25. IssueIndexerName string
  26. IssueQueueType string
  27. IssueQueueDir string
  28. IssueQueueConnStr string
  29. IssueQueueBatchNumber int
  30. StartupTimeout time.Duration
  31. RepoIndexerEnabled bool
  32. RepoType string
  33. RepoPath string
  34. RepoConnStr string
  35. RepoIndexerName string
  36. UpdateQueueLength int
  37. MaxIndexerFileSize int64
  38. IncludePatterns []glob.Glob
  39. ExcludePatterns []glob.Glob
  40. ExcludeVendored bool
  41. }{
  42. IssueType: "bleve",
  43. IssuePath: "indexers/issues.bleve",
  44. IssueConnStr: "",
  45. IssueIndexerName: "gitea_issues",
  46. IssueQueueType: LevelQueueType,
  47. IssueQueueDir: "indexers/issues.queue",
  48. IssueQueueConnStr: "",
  49. IssueQueueBatchNumber: 20,
  50. RepoIndexerEnabled: false,
  51. RepoType: "bleve",
  52. RepoPath: "indexers/repos.bleve",
  53. RepoConnStr: "",
  54. RepoIndexerName: "gitea_codes",
  55. MaxIndexerFileSize: 1024 * 1024,
  56. ExcludeVendored: true,
  57. }
  58. )
  59. func newIndexerService() {
  60. sec := Cfg.Section("indexer")
  61. Indexer.IssueType = sec.Key("ISSUE_INDEXER_TYPE").MustString("bleve")
  62. Indexer.IssuePath = sec.Key("ISSUE_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/issues.bleve"))
  63. if !filepath.IsAbs(Indexer.IssuePath) {
  64. Indexer.IssuePath = path.Join(AppWorkPath, Indexer.IssuePath)
  65. }
  66. Indexer.IssueConnStr = sec.Key("ISSUE_INDEXER_CONN_STR").MustString(Indexer.IssueConnStr)
  67. Indexer.IssueIndexerName = sec.Key("ISSUE_INDEXER_NAME").MustString(Indexer.IssueIndexerName)
  68. Indexer.IssueQueueType = sec.Key("ISSUE_INDEXER_QUEUE_TYPE").MustString(LevelQueueType)
  69. Indexer.IssueQueueDir = sec.Key("ISSUE_INDEXER_QUEUE_DIR").MustString(path.Join(AppDataPath, "indexers/issues.queue"))
  70. Indexer.IssueQueueConnStr = sec.Key("ISSUE_INDEXER_QUEUE_CONN_STR").MustString(path.Join(AppDataPath, ""))
  71. Indexer.IssueQueueBatchNumber = sec.Key("ISSUE_INDEXER_QUEUE_BATCH_NUMBER").MustInt(20)
  72. Indexer.RepoIndexerEnabled = sec.Key("REPO_INDEXER_ENABLED").MustBool(false)
  73. Indexer.RepoType = sec.Key("REPO_INDEXER_TYPE").MustString("bleve")
  74. Indexer.RepoPath = sec.Key("REPO_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/repos.bleve"))
  75. if !filepath.IsAbs(Indexer.RepoPath) {
  76. Indexer.RepoPath = path.Join(AppWorkPath, Indexer.RepoPath)
  77. }
  78. Indexer.RepoConnStr = sec.Key("REPO_INDEXER_CONN_STR").MustString("")
  79. Indexer.RepoIndexerName = sec.Key("REPO_INDEXER_NAME").MustString("gitea_codes")
  80. Indexer.IncludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_INCLUDE").MustString(""))
  81. Indexer.ExcludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_EXCLUDE").MustString(""))
  82. Indexer.ExcludeVendored = sec.Key("REPO_INDEXER_EXCLUDE_VENDORED").MustBool(true)
  83. Indexer.UpdateQueueLength = sec.Key("UPDATE_BUFFER_LEN").MustInt(20)
  84. Indexer.MaxIndexerFileSize = sec.Key("MAX_FILE_SIZE").MustInt64(1024 * 1024)
  85. Indexer.StartupTimeout = sec.Key("STARTUP_TIMEOUT").MustDuration(30 * time.Second)
  86. }
  87. // IndexerGlobFromString parses a comma separated list of patterns and returns a glob.Glob slice suited for repo indexing
  88. func IndexerGlobFromString(globstr string) []glob.Glob {
  89. extarr := make([]glob.Glob, 0, 10)
  90. for _, expr := range strings.Split(strings.ToLower(globstr), ",") {
  91. expr = strings.TrimSpace(expr)
  92. if expr != "" {
  93. if g, err := glob.Compile(expr, '.', '/'); err != nil {
  94. log.Info("Invalid glob expresion '%s' (skipped): %v", expr, err)
  95. } else {
  96. extarr = append(extarr, g)
  97. }
  98. }
  99. }
  100. return extarr
  101. }