forked from forgejo/forgejo
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>
This commit is contained in:
parent
d257485bc0
commit
9bc69ff26e
14 changed files with 694 additions and 164 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue