diff options
author | zeripath <art27@cantab.net> | 2021-11-02 03:14:24 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-02 11:14:24 +0800 |
commit | cb9c8184c9b0967e0b0fbc5eeedec4ba3ae4f020 (patch) | |
tree | fc53b76eb65345529a7ec435d7864601f3681337 | |
parent | e2995ef515fcaa92c7a0c9611d5294e13cf2b875 (diff) | |
download | gitea-cb9c8184c9b0967e0b0fbc5eeedec4ba3ae4f020.tar.gz gitea-cb9c8184c9b0967e0b0fbc5eeedec4ba3ae4f020.zip |
Make Repo Code Indexer an Unique Queue (#17515)
The functioning of the code indexer queue really only makes sense as an unique queue
and doing this allows use to simplify the indexer data to simply delete the data if
the repo is no longer in the db.
Signed-off-by: Andrew Thornton <art27@cantab.net>
-rw-r--r-- | integrations/repo_search_test.go | 1 | ||||
-rw-r--r-- | modules/indexer/code/indexer.go | 34 | ||||
-rw-r--r-- | modules/notification/indexer/indexer.go | 2 |
3 files changed, 12 insertions, 25 deletions
diff --git a/integrations/repo_search_test.go b/integrations/repo_search_test.go index 6f2ee37460..56d89fee30 100644 --- a/integrations/repo_search_test.go +++ b/integrations/repo_search_test.go @@ -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"}) diff --git a/modules/indexer/code/indexer.go b/modules/indexer/code/indexer.go index 46b5905059..981167a825 100644 --- a/modules/indexer/code/indexer.go +++ b/modules/indexer/code/indexer.go @@ -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 } @@ -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") } @@ -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} diff --git a/modules/notification/indexer/indexer.go b/modules/notification/indexer/indexer.go index 205194ad3e..109eb1f62d 100644 --- a/modules/notification/indexer/indexer.go +++ b/modules/notification/indexer/indexer.go @@ -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) } } |