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.

indexer.go 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. RepoPath string
  33. UpdateQueueLength int
  34. MaxIndexerFileSize int64
  35. IncludePatterns []glob.Glob
  36. ExcludePatterns []glob.Glob
  37. ExcludeVendored bool
  38. }{
  39. IssueType: "bleve",
  40. IssuePath: "indexers/issues.bleve",
  41. IssueConnStr: "",
  42. IssueIndexerName: "gitea_issues",
  43. IssueQueueType: LevelQueueType,
  44. IssueQueueDir: "indexers/issues.queue",
  45. IssueQueueConnStr: "",
  46. IssueQueueBatchNumber: 20,
  47. MaxIndexerFileSize: 1024 * 1024,
  48. ExcludeVendored: true,
  49. }
  50. )
  51. func newIndexerService() {
  52. sec := Cfg.Section("indexer")
  53. Indexer.IssueType = sec.Key("ISSUE_INDEXER_TYPE").MustString("bleve")
  54. Indexer.IssuePath = sec.Key("ISSUE_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/issues.bleve"))
  55. if !filepath.IsAbs(Indexer.IssuePath) {
  56. Indexer.IssuePath = path.Join(AppWorkPath, Indexer.IssuePath)
  57. }
  58. Indexer.IssueConnStr = sec.Key("ISSUE_INDEXER_CONN_STR").MustString(Indexer.IssueConnStr)
  59. Indexer.IssueIndexerName = sec.Key("ISSUE_INDEXER_NAME").MustString(Indexer.IssueIndexerName)
  60. Indexer.IssueQueueType = sec.Key("ISSUE_INDEXER_QUEUE_TYPE").MustString(LevelQueueType)
  61. Indexer.IssueQueueDir = sec.Key("ISSUE_INDEXER_QUEUE_DIR").MustString(path.Join(AppDataPath, "indexers/issues.queue"))
  62. Indexer.IssueQueueConnStr = sec.Key("ISSUE_INDEXER_QUEUE_CONN_STR").MustString(path.Join(AppDataPath, ""))
  63. Indexer.IssueQueueBatchNumber = sec.Key("ISSUE_INDEXER_QUEUE_BATCH_NUMBER").MustInt(20)
  64. Indexer.RepoIndexerEnabled = sec.Key("REPO_INDEXER_ENABLED").MustBool(false)
  65. Indexer.RepoPath = sec.Key("REPO_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/repos.bleve"))
  66. if !filepath.IsAbs(Indexer.RepoPath) {
  67. Indexer.RepoPath = path.Join(AppWorkPath, Indexer.RepoPath)
  68. }
  69. Indexer.IncludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_INCLUDE").MustString(""))
  70. Indexer.ExcludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_EXCLUDE").MustString(""))
  71. Indexer.ExcludeVendored = sec.Key("REPO_INDEXER_EXCLUDE_VENDORED").MustBool(true)
  72. Indexer.UpdateQueueLength = sec.Key("UPDATE_BUFFER_LEN").MustInt(20)
  73. Indexer.MaxIndexerFileSize = sec.Key("MAX_FILE_SIZE").MustInt64(1024 * 1024)
  74. Indexer.StartupTimeout = sec.Key("STARTUP_TIMEOUT").MustDuration(30 * time.Second)
  75. }
  76. // IndexerGlobFromString parses a comma separated list of patterns and returns a glob.Glob slice suited for repo indexing
  77. func IndexerGlobFromString(globstr string) []glob.Glob {
  78. extarr := make([]glob.Glob, 0, 10)
  79. for _, expr := range strings.Split(strings.ToLower(globstr), ",") {
  80. expr = strings.TrimSpace(expr)
  81. if expr != "" {
  82. if g, err := glob.Compile(expr, '.', '/'); err != nil {
  83. log.Info("Invalid glob expresion '%s' (skipped): %v", expr, err)
  84. } else {
  85. extarr = append(extarr, g)
  86. }
  87. }
  88. }
  89. return extarr
  90. }