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.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. "code.gitea.io/gitea/modules/log"
  10. "github.com/gobwas/glob"
  11. )
  12. // enumerates all the indexer queue types
  13. const (
  14. LevelQueueType = "levelqueue"
  15. ChannelQueueType = "channel"
  16. RedisQueueType = "redis"
  17. )
  18. var (
  19. // Indexer settings
  20. Indexer = struct {
  21. IssueType string
  22. IssuePath string
  23. RepoIndexerEnabled bool
  24. RepoPath string
  25. UpdateQueueLength int
  26. MaxIndexerFileSize int64
  27. IssueQueueType string
  28. IssueQueueDir string
  29. IssueQueueConnStr string
  30. IssueQueueBatchNumber int
  31. IncludePatterns []glob.Glob
  32. ExcludePatterns []glob.Glob
  33. }{
  34. IssueType: "bleve",
  35. IssuePath: "indexers/issues.bleve",
  36. IssueQueueType: LevelQueueType,
  37. IssueQueueDir: "indexers/issues.queue",
  38. IssueQueueConnStr: "",
  39. IssueQueueBatchNumber: 20,
  40. }
  41. )
  42. func newIndexerService() {
  43. sec := Cfg.Section("indexer")
  44. Indexer.IssueType = sec.Key("ISSUE_INDEXER_TYPE").MustString("bleve")
  45. Indexer.IssuePath = sec.Key("ISSUE_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/issues.bleve"))
  46. if !filepath.IsAbs(Indexer.IssuePath) {
  47. Indexer.IssuePath = path.Join(AppWorkPath, Indexer.IssuePath)
  48. }
  49. Indexer.RepoIndexerEnabled = sec.Key("REPO_INDEXER_ENABLED").MustBool(false)
  50. Indexer.RepoPath = sec.Key("REPO_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/repos.bleve"))
  51. if !filepath.IsAbs(Indexer.RepoPath) {
  52. Indexer.RepoPath = path.Join(AppWorkPath, Indexer.RepoPath)
  53. }
  54. Indexer.IncludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_INCLUDE").MustString(""))
  55. Indexer.ExcludePatterns = IndexerGlobFromString(sec.Key("REPO_INDEXER_EXCLUDE").MustString(""))
  56. Indexer.UpdateQueueLength = sec.Key("UPDATE_BUFFER_LEN").MustInt(20)
  57. Indexer.MaxIndexerFileSize = sec.Key("MAX_FILE_SIZE").MustInt64(1024 * 1024)
  58. Indexer.IssueQueueType = sec.Key("ISSUE_INDEXER_QUEUE_TYPE").MustString(LevelQueueType)
  59. Indexer.IssueQueueDir = sec.Key("ISSUE_INDEXER_QUEUE_DIR").MustString(path.Join(AppDataPath, "indexers/issues.queue"))
  60. Indexer.IssueQueueConnStr = sec.Key("ISSUE_INDEXER_QUEUE_CONN_STR").MustString(path.Join(AppDataPath, ""))
  61. Indexer.IssueQueueBatchNumber = sec.Key("ISSUE_INDEXER_QUEUE_BATCH_NUMBER").MustInt(20)
  62. }
  63. // IndexerGlobFromString parses a comma separated list of patterns and returns a glob.Glob slice suited for repo indexing
  64. func IndexerGlobFromString(globstr string) []glob.Glob {
  65. extarr := make([]glob.Glob, 0, 10)
  66. for _, expr := range strings.Split(strings.ToLower(globstr), ",") {
  67. expr = strings.TrimSpace(expr)
  68. if expr != "" {
  69. if g, err := glob.Compile(expr, '.', '/'); err != nil {
  70. log.Info("Invalid glob expresion '%s' (skipped): %v", expr, err)
  71. } else {
  72. extarr = append(extarr, g)
  73. }
  74. }
  75. }
  76. return extarr
  77. }