summaryrefslogtreecommitdiffstats
path: root/models/issue_indexer.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/issue_indexer.go')
-rw-r--r--models/issue_indexer.go37
1 files changed, 23 insertions, 14 deletions
diff --git a/models/issue_indexer.go b/models/issue_indexer.go
index 1e14268a0e..b58c9dc2d1 100644
--- a/models/issue_indexer.go
+++ b/models/issue_indexer.go
@@ -25,6 +25,7 @@ func InitIssueIndexer() {
// populateIssueIndexer populate the issue indexer with issue data
func populateIssueIndexer() error {
+ batch := indexer.IssueIndexerBatch()
for page := 1; ; page++ {
repos, _, err := Repositories(&SearchRepoOptions{
Page: page,
@@ -34,7 +35,7 @@ func populateIssueIndexer() error {
return fmt.Errorf("Repositories: %v", err)
}
if len(repos) == 0 {
- return nil
+ return batch.Flush()
}
for _, repo := range repos {
issues, err := Issues(&IssuesOptions{
@@ -42,29 +43,37 @@ func populateIssueIndexer() error {
IsClosed: util.OptionalBoolNone,
IsPull: util.OptionalBoolNone,
})
- updates := make([]indexer.IssueIndexerUpdate, len(issues))
- for i, issue := range issues {
- updates[i] = issue.update()
+ if err != nil {
+ return err
}
- if err = indexer.BatchUpdateIssues(updates...); err != nil {
- return fmt.Errorf("BatchUpdate: %v", err)
+ for _, issue := range issues {
+ if err := batch.Add(issue.update()); err != nil {
+ return err
+ }
}
}
}
}
func processIssueIndexerUpdateQueue() {
+ batch := indexer.IssueIndexerBatch()
for {
+ var issueID int64
select {
- case issueID := <-issueIndexerUpdateQueue:
- issue, err := GetIssueByID(issueID)
- if err != nil {
- log.Error(4, "issuesIndexer.Index: %v", err)
- continue
- }
- if err = indexer.UpdateIssue(issue.update()); err != nil {
- log.Error(4, "issuesIndexer.Index: %v", err)
+ case issueID = <-issueIndexerUpdateQueue:
+ default:
+ // flush whatever updates we currently have, since we
+ // might have to wait a while
+ if err := batch.Flush(); err != nil {
+ log.Error(4, "IssueIndexer: %v", err)
}
+ issueID = <-issueIndexerUpdateQueue
+ }
+ issue, err := GetIssueByID(issueID)
+ if err != nil {
+ log.Error(4, "GetIssueByID: %v", err)
+ } else if err = batch.Add(issue.update()); err != nil {
+ log.Error(4, "IssueIndexer: %v", err)
}
}
}