diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-09-24 17:08:48 -0700 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2017-09-25 03:08:48 +0300 |
commit | fa28de820e3ee70a2a0b6aa9c9cfa358675b3874 (patch) | |
tree | 3f67133fbbd184f58669881a931d87b31c153b0c /models | |
parent | 0b0d85c90d609b84b26dc4f6ae31c4652f9243bb (diff) | |
download | gitea-fa28de820e3ee70a2a0b6aa9c9cfa358675b3874.tar.gz gitea-fa28de820e3ee70a2a0b6aa9c9cfa358675b3874.zip |
Make indexer code more reusable (#2590)
Diffstat (limited to 'models')
-rw-r--r-- | models/issue_indexer.go | 37 |
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) } } } |