Skip to content

Commit a1d796f

Browse files
authored
Index code and stats only for non-empty repositories (#10251)
Fix test and switch to unique queue Fix MySQL support when deleting old statistics
1 parent ff261da commit a1d796f

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

models/fixtures/repository.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
owner_name: user2
55
lower_name: repo1
66
name: repo1
7+
is_empty: false
78
is_private: false
89
num_issues: 2
910
num_closed_issues: 1

models/repo_indexer.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ func GetUnindexedRepos(indexerType RepoIndexerType, maxRepoID int64, page, pageS
3434
ids := make([]int64, 0, 50)
3535
cond := builder.Cond(builder.IsNull{
3636
"repo_indexer_status.id",
37+
}).And(builder.Eq{
38+
"repository.is_empty": false,
3739
})
3840
sess := x.Table("repository").Join("LEFT OUTER", "repo_indexer_status", "repository.id = repo_indexer_status.repo_id AND repo_indexer_status.indexer_type = ?", indexerType)
3941
if maxRepoID > 0 {
@@ -66,11 +68,11 @@ func (repo *Repository) getIndexerStatus(e Engine, indexerType RepoIndexerType)
6668
return repo.StatsIndexerStatus, nil
6769
}
6870
}
69-
status := &RepoIndexerStatus{RepoID: repo.ID, IndexerType: indexerType}
70-
has, err := e.Get(status)
71-
if err != nil {
71+
status := &RepoIndexerStatus{RepoID: repo.ID}
72+
if has, err := e.Where("`indexer_type` = ?", indexerType).Get(status); err != nil {
7273
return nil, err
7374
} else if !has {
75+
status.IndexerType = indexerType
7476
status.CommitSha = ""
7577
}
7678
switch indexerType {

models/repo_language_stats.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,19 @@ func (repo *Repository) UpdateLanguageStats(commitID string, stats map[string]fl
125125
}
126126
}
127127
// Delete old languages
128-
if _, err := sess.Where("`id` IN (SELECT `id` FROM `language_stat` WHERE `repo_id` = ? AND `commit_id` != ?)", repo.ID, commitID).Delete(&LanguageStat{}); err != nil {
129-
return err
128+
statsToDelete := make([]int64, 0, len(oldstats))
129+
for _, s := range oldstats {
130+
if s.CommitID != commitID {
131+
statsToDelete = append(statsToDelete, s.ID)
132+
}
133+
}
134+
if len(statsToDelete) > 0 {
135+
if _, err := sess.In("`id`", statsToDelete).Delete(&LanguageStat{}); err != nil {
136+
return err
137+
}
130138
}
131139

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

modules/indexer/stats/queue.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
// statsQueue represents a queue to handle repository stats updates
17-
var statsQueue queue.Queue
17+
var statsQueue queue.UniqueQueue
1818

1919
// handle passed PR IDs and test the PRs
2020
func handle(data ...queue.Data) {
@@ -27,7 +27,7 @@ func handle(data ...queue.Data) {
2727
}
2828

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

0 commit comments

Comments
 (0)