Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Repo Code Indexer an Unique Queue #17515

Merged
merged 1 commit into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion integrations/repo_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func TestSearchRepo(t *testing.T) {
repo, err = models.GetRepositoryByOwnerAndName("user2", "glob")
assert.NoError(t, err)

executeIndexer(t, repo, code_indexer.DeleteRepoFromIndexer)
executeIndexer(t, repo, code_indexer.UpdateRepoIndexer)

testSearch(t, "/user2/glob/search?q=loren&page=1", []string{"a.txt"})
Expand Down
34 changes: 11 additions & 23 deletions modules/indexer/code/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,18 @@ func filenameOfIndexerID(indexerID string) string {

// IndexerData represents data stored in the code indexer
type IndexerData struct {
RepoID int64
IsDelete bool
RepoID int64
}

var (
indexerQueue queue.Queue
indexerQueue queue.UniqueQueue
)

func index(indexer Indexer, repoID int64) error {
repo, err := models.GetRepositoryByID(repoID)
if models.IsErrRepoNotExist(err) {
return indexer.Delete(repoID)
}
if err != nil {
return err
}
Expand Down Expand Up @@ -146,22 +148,16 @@ func Init() {
log.Error("Unable to process provided datum: %v - not possible to cast to IndexerData", datum)
continue
}
log.Trace("IndexerData Process: %v %t", indexerData.RepoID, indexerData.IsDelete)

if indexerData.IsDelete {
if err := indexer.Delete(indexerData.RepoID); err != nil {
log.Error("indexer.Delete: %v", err)
}
} else {
if err := index(indexer, indexerData.RepoID); err != nil {
log.Error("index: %v", err)
continue
}
log.Trace("IndexerData Process Repo: %d", indexerData.RepoID)

if err := index(indexer, indexerData.RepoID); err != nil {
log.Error("index: %v", err)
continue
}
}
}

indexerQueue = queue.CreateQueue("code_indexer", handler, &IndexerData{})
indexerQueue = queue.CreateUniqueQueue("code_indexer", handler, &IndexerData{})
if indexerQueue == nil {
log.Fatal("Unable to create codes indexer queue")
}
Expand Down Expand Up @@ -265,14 +261,6 @@ func Init() {
}
}

// DeleteRepoFromIndexer remove all of a repository's entries from the indexer
func DeleteRepoFromIndexer(repo *models.Repository) {
indexData := &IndexerData{RepoID: repo.ID, IsDelete: true}
if err := indexerQueue.Push(indexData); err != nil {
log.Error("Delete repo index data %v failed: %v", indexData, err)
}
}

// UpdateRepoIndexer update a repository's entries in the indexer
func UpdateRepoIndexer(repo *models.Repository) {
indexData := &IndexerData{RepoID: repo.ID}
Expand Down
2 changes: 1 addition & 1 deletion modules/notification/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (r *indexerNotifier) NotifyDeleteComment(doer *models.User, comment *models
func (r *indexerNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
issue_indexer.DeleteRepoIssueIndexer(repo)
if setting.Indexer.RepoIndexerEnabled {
code_indexer.DeleteRepoFromIndexer(repo)
code_indexer.UpdateRepoIndexer(repo)
}
}

Expand Down