Skip to content

Commit 2e89743

Browse files
committed
split indexer setting to a seperate file
1 parent 9a442e6 commit 2e89743

File tree

3 files changed

+57
-42
lines changed

3 files changed

+57
-42
lines changed

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,4 @@ ignored = ["google.golang.org/appengine*"]
112112

113113
[[constraint]]
114114
name = "github.com/prometheus/client_golang"
115-
version = "0.9.0"
115+
version = "0.9.0"

modules/setting/indexer.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
5+
package setting
6+
7+
import (
8+
"path"
9+
"path/filepath"
10+
)
11+
12+
// enumerates all the indexer queue types
13+
const (
14+
LevelQueueType = "levelqueue"
15+
ChannelQueueType = "channel"
16+
)
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+
IssueIndexerQueueType string
28+
IssueIndexerQueueDir string
29+
IssueIndexerQueueBatchNumber int
30+
}{
31+
IssueType: "bleve",
32+
IssuePath: "indexers/issues.bleve",
33+
IssueIndexerQueueType: LevelQueueType,
34+
IssueIndexerQueueDir: "indexers/issues.queue",
35+
IssueIndexerQueueBatchNumber: 20,
36+
}
37+
)
38+
39+
func newIndexerService() {
40+
sec := Cfg.Section("indexer")
41+
Indexer.IssuePath = sec.Key("ISSUE_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/issues.bleve"))
42+
if !filepath.IsAbs(Indexer.IssuePath) {
43+
Indexer.IssuePath = path.Join(AppWorkPath, Indexer.IssuePath)
44+
}
45+
Indexer.RepoIndexerEnabled = sec.Key("REPO_INDEXER_ENABLED").MustBool(false)
46+
Indexer.RepoPath = sec.Key("REPO_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/repos.bleve"))
47+
if !filepath.IsAbs(Indexer.RepoPath) {
48+
Indexer.RepoPath = path.Join(AppWorkPath, Indexer.RepoPath)
49+
}
50+
Indexer.UpdateQueueLength = sec.Key("UPDATE_BUFFER_LEN").MustInt(20)
51+
Indexer.MaxIndexerFileSize = sec.Key("MAX_FILE_SIZE").MustInt64(1024 * 1024)
52+
Indexer.IssueIndexerQueueType = sec.Key("ISSUE_INDEXER_QUEUE_TYPE").MustString(LevelQueueType)
53+
Indexer.IssueIndexerQueueDir = sec.Key("ISSUE_INDEXER_QUEUE_DIR").MustString(path.Join(AppDataPath, "indexers/issues.queue"))
54+
Indexer.IssueIndexerQueueBatchNumber = sec.Key("ISSUE_INDEXER_QUEUE_BATCH_NUMBER").MustInt(20)
55+
}

modules/setting/setting.go

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ const (
8383
ReCaptcha = "recaptcha"
8484
)
8585

86-
// enumerates all the indexer queue types
87-
const (
88-
LevelQueueType = "levelqueue"
89-
ChannelQueueType = "channel"
90-
)
91-
9286
// settings
9387
var (
9488
// AppVer settings
@@ -185,25 +179,6 @@ var (
185179
DBConnectRetries int
186180
DBConnectBackoff time.Duration
187181

188-
// Indexer settings
189-
Indexer = struct {
190-
IssueType string
191-
IssuePath string
192-
RepoIndexerEnabled bool
193-
RepoPath string
194-
UpdateQueueLength int
195-
MaxIndexerFileSize int64
196-
IssueIndexerQueueType string
197-
IssueIndexerQueueDir string
198-
IssueIndexerQueueBatchNumber int
199-
}{
200-
IssueType: "bleve",
201-
IssuePath: "indexers/issues.bleve",
202-
IssueIndexerQueueType: LevelQueueType,
203-
IssueIndexerQueueDir: "indexers/issues.queue",
204-
IssueIndexerQueueBatchNumber: 20,
205-
}
206-
207182
// Repository settings
208183
Repository = struct {
209184
AnsiCharset string
@@ -1232,22 +1207,6 @@ func NewContext() {
12321207
// Explicitly disable credential helper, otherwise Git credentials might leak
12331208
git.GlobalCommandArgs = append(git.GlobalCommandArgs, "-c", "credential.helper=")
12341209
}
1235-
1236-
sec = Cfg.Section("indexer")
1237-
Indexer.IssuePath = sec.Key("ISSUE_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/issues.bleve"))
1238-
if !filepath.IsAbs(Indexer.IssuePath) {
1239-
Indexer.IssuePath = path.Join(AppWorkPath, Indexer.IssuePath)
1240-
}
1241-
Indexer.RepoIndexerEnabled = sec.Key("REPO_INDEXER_ENABLED").MustBool(false)
1242-
Indexer.RepoPath = sec.Key("REPO_INDEXER_PATH").MustString(path.Join(AppDataPath, "indexers/repos.bleve"))
1243-
if !filepath.IsAbs(Indexer.RepoPath) {
1244-
Indexer.RepoPath = path.Join(AppWorkPath, Indexer.RepoPath)
1245-
}
1246-
Indexer.UpdateQueueLength = sec.Key("UPDATE_BUFFER_LEN").MustInt(20)
1247-
Indexer.MaxIndexerFileSize = sec.Key("MAX_FILE_SIZE").MustInt64(1024 * 1024)
1248-
Indexer.IssueIndexerQueueType = sec.Key("ISSUE_INDEXER_QUEUE_TYPE").MustString(LevelQueueType)
1249-
Indexer.IssueIndexerQueueDir = sec.Key("ISSUE_INDEXER_QUEUE_DIR").MustString(path.Join(AppDataPath, "indexers/issues.queue"))
1250-
Indexer.IssueIndexerQueueBatchNumber = sec.Key("ISSUE_INDEXER_QUEUE_BATCH_NUMBER").MustInt(20)
12511210
}
12521211

12531212
// NewServices initializes the services
@@ -1261,4 +1220,5 @@ func NewServices() {
12611220
newRegisterMailService()
12621221
newNotifyMailService()
12631222
newWebhookService()
1223+
newIndexerService()
12641224
}

0 commit comments

Comments
 (0)