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

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

Merged
merged 1 commit into from
Feb 14, 2020
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
Index code and stats only for non-empty repositories
Fix test and switch to unique queue

Fix MySQL support when deleting old statistics
  • Loading branch information
lafriks committed Feb 14, 2020
commit cb4770b51176caa85f2084bc9fabc56df1973b9a
1 change: 1 addition & 0 deletions models/fixtures/repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
owner_name: user2
lower_name: repo1
name: repo1
is_empty: false
is_private: false
num_issues: 2
num_closed_issues: 1
Expand Down
8 changes: 5 additions & 3 deletions models/repo_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func GetUnindexedRepos(indexerType RepoIndexerType, maxRepoID int64, page, pageS
ids := make([]int64, 0, 50)
cond := builder.Cond(builder.IsNull{
"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)
if maxRepoID > 0 {
Expand Down Expand Up @@ -66,11 +68,11 @@ func (repo *Repository) getIndexerStatus(e Engine, indexerType RepoIndexerType)
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
} else if !has {
status.IndexerType = indexerType
status.CommitSha = ""
}
switch indexerType {
Expand Down
13 changes: 11 additions & 2 deletions models/repo_language_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,19 @@ func (repo *Repository) UpdateLanguageStats(commitID string, stats map[string]fl
}
}
// 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 {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions modules/indexer/stats/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

// 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
func handle(data ...queue.Data) {
Expand All @@ -27,7 +27,7 @@ func handle(data ...queue.Data) {
}

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 {
return fmt.Errorf("Unable to create repo_stats_update Queue")
}
Expand Down