|
|
|
@ -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) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|