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.

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