Skip to content

Commit b3b82c2

Browse files
committed
fix bug
1 parent 961318b commit b3b82c2

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

models/issue_indexer.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ func InitIssueIndexer() error {
2626
if err != nil {
2727
return err
2828
}
29-
3029
if !exist {
3130
go populateIssueIndexer()
3231
}

models/unit_tests.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ func MainTest(m *testing.M, pathToGiteaRoot string) {
4444
fatalTestError("Error creating test engine: %v\n", err)
4545
}
4646

47+
if err = InitIssueIndexer(); err != nil {
48+
fatalTestError("Error InitIssueIndexer: %v\n", err)
49+
}
50+
4751
setting.AppURL = "https://try.gitea.io/"
4852
setting.RunUser = "runuser"
4953
setting.SSH.Port = 3000

modules/indexer/issues/queue_ledis_local.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ func (l *LedisLocalQueue) Run() error {
6060
continue
6161
}
6262

63+
i++
64+
if len(datas) > l.batchNumber || (len(datas) > 0 && i > 3) {
65+
l.indexer.Index(datas)
66+
datas = make([]*IndexerData, 0, l.batchNumber)
67+
i = 0
68+
}
69+
6370
if len(bs) <= 0 {
6471
time.Sleep(time.Millisecond * 100)
6572
continue
@@ -76,14 +83,7 @@ func (l *LedisLocalQueue) Run() error {
7683
log.Trace("LedisLocalQueue: task found: %#v", data)
7784

7885
datas = append(datas, &data)
79-
i++
80-
81-
if len(datas) > l.batchNumber || i > 3 {
82-
l.indexer.Index(datas)
83-
datas = make([]*IndexerData, 0, l.batchNumber)
84-
i = 0
85-
}
86-
time.Sleep(time.Millisecond * 100)
86+
time.Sleep(time.Millisecond * 10)
8787
}
8888
}
8989

modules/setting/setting.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ var (
186186
DBConnectBackoff time.Duration
187187

188188
// Indexer settings
189-
Indexer struct {
189+
Indexer = struct {
190190
IssuePath string
191191
RepoIndexerEnabled bool
192192
RepoPath string
@@ -196,6 +196,12 @@ var (
196196
IssueIndexerQueueDir string
197197
IssueIndexerQueueDBIndex int
198198
IssueIndexerQueueBatchNumber int
199+
}{
200+
IssuePath: "indexers/issues.bleve",
201+
IssueIndexerQueueType: LedisLocalQueueType,
202+
IssueIndexerQueueDir: "indexers/issues.queue",
203+
IssueIndexerQueueBatchNumber: 20,
204+
IssueIndexerQueueDBIndex: 0,
199205
}
200206

201207
// Repository settings

routers/init.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ func GlobalInit() {
9090

9191
// Booting long running goroutines.
9292
cron.NewContext()
93-
models.InitIssueIndexer()
93+
if err := models.InitIssueIndexer(); err != nil {
94+
log.Fatal(4, "Failed to initialize issue indexer: %v", err)
95+
}
9496
models.InitRepoIndexer()
9597
models.InitSyncMirrors()
9698
models.InitDeliverHooks()

0 commit comments

Comments
 (0)