本站源代码
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

90 líneas
3.1KB

  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. }
  43. )
  44. func newIndexerService() {
  45. sec := Cfg.Section("indexer")
  46. Indexer.IssueType = sec.Key("ISSUE_INDEXER_TYPE").MustString("bleve")
  47. Indexer.IssuePath = sec.Key("ISSUE_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/issues.bleve"))
  48. if !filepath.IsAbs(Indexer.IssuePath) {
  49. Indexer.IssuePath = path.Join(AppWorkPath, Indexer.IssuePath)
  50. }
  51. Indexer.RepoIndexerEnabled = sec.Key("REPO_INDEXER_ENABLED").MustBool(false)
  52. Indexer.RepoPath = sec.Key("REPO_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/repos.bleve"))
  53. if !filepath.IsAbs(Indexer.RepoPath) {
  54. Indexer.RepoPath = path.Join(AppWorkPath, Indexer.RepoPath)
  55. }
  56. Indexer.IncludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_INCLUDE").MustString(""))
  57. Indexer.ExcludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_EXCLUDE").MustString(""))
  58. Indexer.UpdateQueueLength = sec.Key("UPDATE_BUFFER_LEN").MustInt(20)
  59. Indexer.MaxIndexerFileSize = sec.Key("MAX_FILE_SIZE").MustInt64(1024 * 1024)
  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.StartupTimeout = sec.Key("STARTUP_TIMEOUT").MustDuration(30 * time.Second)
  65. }
  66. // IndexerGlobFromString parses a comma separated list of patterns and returns a glob.Glob slice suited for repo indexing
  67. func IndexerGlobFromString(globstr string) []glob.Glob {
  68. extarr := make([]glob.Glob, 0, 10)
  69. for _, expr := range strings.Split(strings.ToLower(globstr), ",") {
  70. expr = strings.TrimSpace(expr)
  71. if expr != "" {
  72. if g, err := glob.Compile(expr, '.', '/'); err != nil {
  73. log.Info("Invalid glob expresion '%s' (skipped): %v", expr, err)
  74. } else {
  75. extarr = append(extarr, g)
  76. }
  77. }
  78. }
  79. return extarr
  80. }
上海开阖软件有限公司 沪ICP备12045867号-1