Ver código fonte

Index code and stats only for non-empty repositories (#10251)

Fix test and switch to unique queue

Fix MySQL support when deleting old statistics
tags/v1.10.5
Lauris BH 4 anos atrás
pai
commit
a1d796f521
Nenhuma conta vinculada ao e-mail do autor do commit

+ 1
- 0
models/fixtures/repository.yml Ver arquivo

owner_name: user2 owner_name: user2
lower_name: repo1 lower_name: repo1
name: repo1 name: repo1
is_empty: false
is_private: false is_private: false
num_issues: 2 num_issues: 2
num_closed_issues: 1 num_closed_issues: 1

+ 5
- 3
models/repo_indexer.go Ver arquivo

ids := make([]int64, 0, 50) ids := make([]int64, 0, 50)
cond := builder.Cond(builder.IsNull{ cond := builder.Cond(builder.IsNull{
"repo_indexer_status.id", "repo_indexer_status.id",
}).And(builder.Eq{
"repository.is_empty": false,
}) })
sess := x.Table("repository").Join("LEFT OUTER", "repo_indexer_status", "repository.id = repo_indexer_status.repo_id AND repo_indexer_status.indexer_type = ?", indexerType) sess := x.Table("repository").Join("LEFT OUTER", "repo_indexer_status", "repository.id = repo_indexer_status.repo_id AND repo_indexer_status.indexer_type = ?", indexerType)
if maxRepoID > 0 { if maxRepoID > 0 {
return repo.StatsIndexerStatus, nil return repo.StatsIndexerStatus, nil
} }
} }
status := &RepoIndexerStatus{RepoID: repo.ID, IndexerType: indexerType}
has, err := e.Get(status)
if err != nil {
status := &RepoIndexerStatus{RepoID: repo.ID}
if has, err := e.Where("`indexer_type` = ?", indexerType).Get(status); err != nil {
return nil, err return nil, err
} else if !has { } else if !has {
status.IndexerType = indexerType
status.CommitSha = "" status.CommitSha = ""
} }
switch indexerType { switch indexerType {

+ 11
- 2
models/repo_language_stats.go Ver arquivo

} }
} }
// Delete old languages // Delete old languages
if _, err := sess.Where("`id` IN (SELECT `id` FROM `language_stat` WHERE `repo_id` = ? AND `commit_id` != ?)", repo.ID, commitID).Delete(&LanguageStat{}); err != nil {
return err
statsToDelete := make([]int64, 0, len(oldstats))
for _, s := range oldstats {
if s.CommitID != commitID {
statsToDelete = append(statsToDelete, s.ID)
}
}
if len(statsToDelete) > 0 {
if _, err := sess.In("`id`", statsToDelete).Delete(&LanguageStat{}); err != nil {
return err
}
} }


// Update indexer status
if err = repo.updateIndexerStatus(sess, RepoIndexerTypeStats, commitID); err != nil { if err = repo.updateIndexerStatus(sess, RepoIndexerTypeStats, commitID); err != nil {
return err return err
} }

+ 2
- 2
modules/indexer/stats/queue.go Ver arquivo

) )


// statsQueue represents a queue to handle repository stats updates // statsQueue represents a queue to handle repository stats updates
var statsQueue queue.Queue
var statsQueue queue.UniqueQueue


// handle passed PR IDs and test the PRs // handle passed PR IDs and test the PRs
func handle(data ...queue.Data) { func handle(data ...queue.Data) {
} }


func initStatsQueue() error { func initStatsQueue() error {
statsQueue = queue.CreateQueue("repo_stats_update", handle, int64(0)).(queue.Queue)
statsQueue = queue.CreateUniqueQueue("repo_stats_update", handle, int64(0)).(queue.UniqueQueue)
if statsQueue == nil { if statsQueue == nil {
return fmt.Errorf("Unable to create repo_stats_update Queue") return fmt.Errorf("Unable to create repo_stats_update Queue")
} }

Carregando…
Cancelar
Salvar