fix indexer reindex bug when gitea restart (#5563)

* fix issue indexer bug reindex when restart gitea

* also fix code indexer reindex when gitea restart
This commit is contained in:
Lunny Xiao 2018-12-19 16:37:48 +08:00 committed by GitHub
parent c64963553a
commit b65e37ed72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions

View file

@ -60,7 +60,7 @@ func InitIssueIndexer(populateIndexer func() error) {
return return
} }
if err = createIssueIndexer(); err != nil { if err = createIssueIndexer(setting.Indexer.IssuePath, issueIndexerLatestVersion); err != nil {
log.Fatal(4, "InitIssuesIndexer: create index, %v", err) log.Fatal(4, "InitIssuesIndexer: create index, %v", err)
} }
if err = populateIndexer(); err != nil { if err = populateIndexer(); err != nil {
@ -69,7 +69,7 @@ func InitIssueIndexer(populateIndexer func() error) {
} }
// createIssueIndexer create an issue indexer if one does not already exist // createIssueIndexer create an issue indexer if one does not already exist
func createIssueIndexer() error { func createIssueIndexer(path string, latestVersion int) error {
mapping := bleve.NewIndexMapping() mapping := bleve.NewIndexMapping()
docMapping := bleve.NewDocumentMapping() docMapping := bleve.NewDocumentMapping()
@ -100,10 +100,16 @@ func createIssueIndexer() error {
mapping.AddDocumentMapping("_all", bleve.NewDocumentDisabledMapping()) mapping.AddDocumentMapping("_all", bleve.NewDocumentDisabledMapping())
var err error var err error
issueIndexer, err = bleve.New(setting.Indexer.IssuePath, mapping) issueIndexer, err = bleve.New(path, mapping)
if err != nil {
return err return err
} }
return rupture.WriteIndexMetadata(path, &rupture.IndexMetadata{
Version: latestVersion,
})
}
// IssueIndexerBatch batch to add updates to // IssueIndexerBatch batch to add updates to
func IssueIndexerBatch() rupture.FlushingBatch { func IssueIndexerBatch() rupture.FlushingBatch {
return rupture.NewFlushingBatch(issueIndexer, maxBatchSize) return rupture.NewFlushingBatch(issueIndexer, maxBatchSize)

View file

@ -84,7 +84,7 @@ func InitRepoIndexer(populateIndexer func() error) {
return return
} }
if err = createRepoIndexer(); err != nil { if err = createRepoIndexer(setting.Indexer.RepoPath, repoIndexerLatestVersion); err != nil {
log.Fatal(4, "CreateRepoIndexer: %v", err) log.Fatal(4, "CreateRepoIndexer: %v", err)
} }
if err = populateIndexer(); err != nil { if err = populateIndexer(); err != nil {
@ -93,7 +93,7 @@ func InitRepoIndexer(populateIndexer func() error) {
} }
// createRepoIndexer create a repo indexer if one does not already exist // createRepoIndexer create a repo indexer if one does not already exist
func createRepoIndexer() error { func createRepoIndexer(path string, latestVersion int) error {
var err error var err error
docMapping := bleve.NewDocumentMapping() docMapping := bleve.NewDocumentMapping()
numericFieldMapping := bleve.NewNumericFieldMapping() numericFieldMapping := bleve.NewNumericFieldMapping()
@ -119,9 +119,14 @@ func createRepoIndexer() error {
mapping.AddDocumentMapping(repoIndexerDocType, docMapping) mapping.AddDocumentMapping(repoIndexerDocType, docMapping)
mapping.AddDocumentMapping("_all", bleve.NewDocumentDisabledMapping()) mapping.AddDocumentMapping("_all", bleve.NewDocumentDisabledMapping())
repoIndexer, err = bleve.New(setting.Indexer.RepoPath, mapping) repoIndexer, err = bleve.New(path, mapping)
if err != nil {
return err return err
} }
return rupture.WriteIndexMetadata(path, &rupture.IndexMetadata{
Version: latestVersion,
})
}
func filenameIndexerID(repoID int64, filename string) string { func filenameIndexerID(repoID int64, filename string) string {
return indexerID(repoID) + "_" + filename return indexerID(repoID) + "_" + filename