aboutsummaryrefslogtreecommitdiffstats
path: root/modules/indexer/code/queue.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-08-31 00:08:01 +0800
committerGitHub <noreply@github.com>2020-08-30 19:08:01 +0300
commit9bc69ff26eeebaf3b622d62d18c757ff1f401dda (patch)
tree69ff71d9d460e83a6fff54b172b604732ab5d065 /modules/indexer/code/queue.go
parentd257485bc0026c9717fe7bf4c9953ad1b7a1a9ae (diff)
downloadgitea-9bc69ff26eeebaf3b622d62d18c757ff1f401dda.tar.gz
gitea-9bc69ff26eeebaf3b622d62d18c757ff1f401dda.zip
Support elastic search for code search (#10273)
* Support elastic search for code search * Finished elastic search implementation and add some tests * Enable test on drone and added docs * Add new fields to elastic search * Fix bug * remove unused changes * Use indexer alias to keep the gitea indexer version * Improve codes * Some code improvements * The real indexer name changed to xxx.v1 Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'modules/indexer/code/queue.go')
-rw-r--r--modules/indexer/code/queue.go30
1 files changed, 25 insertions, 5 deletions
diff --git a/modules/indexer/code/queue.go b/modules/indexer/code/queue.go
index 94675559ea..844003e1fc 100644
--- a/modules/indexer/code/queue.go
+++ b/modules/indexer/code/queue.go
@@ -10,7 +10,6 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
- "code.gitea.io/gitea/modules/setting"
)
type repoIndexerOperation struct {
@@ -25,6 +24,30 @@ func initQueue(queueLength int) {
repoIndexerOperationQueue = make(chan repoIndexerOperation, queueLength)
}
+func index(indexer Indexer, repoID int64) error {
+ repo, err := models.GetRepositoryByID(repoID)
+ if err != nil {
+ return err
+ }
+
+ sha, err := getDefaultBranchSha(repo)
+ if err != nil {
+ return err
+ }
+ changes, err := getRepoChanges(repo, sha)
+ if err != nil {
+ return err
+ } else if changes == nil {
+ return nil
+ }
+
+ if err := indexer.Index(repo, sha, changes); err != nil {
+ return err
+ }
+
+ return repo.UpdateIndexerStatus(models.RepoIndexerTypeCode, sha)
+}
+
func processRepoIndexerOperationQueue(indexer Indexer) {
for {
select {
@@ -35,7 +58,7 @@ func processRepoIndexerOperationQueue(indexer Indexer) {
log.Error("indexer.Delete: %v", err)
}
} else {
- if err = indexer.Index(op.repoID); err != nil {
+ if err = index(indexer, op.repoID); err != nil {
log.Error("indexer.Index: %v", err)
}
}
@@ -60,9 +83,6 @@ func UpdateRepoIndexer(repo *models.Repository, watchers ...chan<- error) {
}
func addOperationToQueue(op repoIndexerOperation) {
- if !setting.Indexer.RepoIndexerEnabled {
- return
- }
select {
case repoIndexerOperationQueue <- op:
break