Skip to content

Commit 3a91f84

Browse files
singulierezeripath6543lunnywxiaoguang
authored
remove redundant call to UpdateRepoStats during migration (#18591)
There is no need to call UpdateRepoStats in the InsertIssues and InsertPullRequests function. They are only called during migration by the CreateIssues and CreateReviews methods of the gitea uploader. The UpdateRepoStats function will be called by the Finish method of the gitea uploader after all reviews and issues are inserted. Calling it before is therefore redundant and the associated SQL requests are not cheap. The statistics tests done after inserting an issue or a pull request are also removed. They predate the implementation of UpdateRepoStats, back when the calculation of the statistics was an integral part of the migration function. The UpdateRepoStats is now tested independantly and these tests are no longer necessary. Signed-off-by: singuliere <[email protected]> Co-authored-by: zeripath <[email protected]> Co-authored-by: 6543 <[email protected]> Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent 5faf055 commit 3a91f84

File tree

2 files changed

+4
-36
lines changed

2 files changed

+4
-36
lines changed

models/migrate.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ func InsertIssues(issues ...*Issue) error {
5252
return err
5353
}
5454
}
55-
err = UpdateRepoStats(ctx, issues[0].RepoID)
56-
if err != nil {
57-
return err
58-
}
5955
return committer.Commit()
6056
}
6157

@@ -147,11 +143,6 @@ func InsertPullRequests(prs ...*PullRequest) error {
147143
return err
148144
}
149145
}
150-
151-
err = UpdateRepoStats(ctx, prs[0].Issue.RepoID)
152-
if err != nil {
153-
return err
154-
}
155146
return committer.Commit()
156147
}
157148

models/migrate_test.go

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ func TestMigrate_InsertMilestones(t *testing.T) {
3232
unittest.CheckConsistencyFor(t, &Milestone{})
3333
}
3434

35-
func assertCreateIssues(t *testing.T, reponame string, isPull bool) {
35+
func assertCreateIssues(t *testing.T, isPull bool) {
3636
assert.NoError(t, unittest.PrepareTestDatabase())
37+
reponame := "repo1"
3738
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame}).(*repo_model.Repository)
3839
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}).(*user_model.User)
3940
label := unittest.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
@@ -63,38 +64,14 @@ func assertCreateIssues(t *testing.T, reponame string, isPull bool) {
6364

6465
i := unittest.AssertExistsAndLoadBean(t, &Issue{Title: title}).(*Issue)
6566
unittest.AssertExistsAndLoadBean(t, &Reaction{Type: "heart", UserID: owner.ID, IssueID: i.ID})
66-
67-
labelModified := unittest.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
68-
assert.EqualValues(t, label.NumIssues+1, labelModified.NumIssues)
69-
assert.EqualValues(t, label.NumClosedIssues+1, labelModified.NumClosedIssues)
70-
71-
milestoneModified := unittest.AssertExistsAndLoadBean(t, &Milestone{ID: milestone.ID}).(*Milestone)
72-
assert.EqualValues(t, milestone.NumIssues+1, milestoneModified.NumIssues)
73-
assert.EqualValues(t, milestone.NumClosedIssues+1, milestoneModified.NumClosedIssues)
7467
}
7568

7669
func TestMigrate_CreateIssuesIsPullFalse(t *testing.T) {
77-
assert.NoError(t, unittest.PrepareTestDatabase())
78-
reponame := "repo1"
79-
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame}).(*repo_model.Repository)
80-
81-
assertCreateIssues(t, reponame, false)
82-
83-
repoModified := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repo.ID}).(*repo_model.Repository)
84-
assert.EqualValues(t, repo.NumIssues+1, repoModified.NumIssues)
85-
assert.EqualValues(t, repo.NumClosedIssues+1, repoModified.NumClosedIssues)
70+
assertCreateIssues(t, false)
8671
}
8772

8873
func TestMigrate_CreateIssuesIsPullTrue(t *testing.T) {
89-
assert.NoError(t, unittest.PrepareTestDatabase())
90-
reponame := "repo1"
91-
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame}).(*repo_model.Repository)
92-
93-
assertCreateIssues(t, reponame, true)
94-
95-
repoModified := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repo.ID}).(*repo_model.Repository)
96-
assert.EqualValues(t, repo.NumPulls+1, repoModified.NumPulls)
97-
assert.EqualValues(t, repo.NumClosedPulls+1, repoModified.NumClosedPulls)
74+
assertCreateIssues(t, true)
9875
}
9976

10077
func TestMigrate_InsertIssueComments(t *testing.T) {

0 commit comments

Comments
 (0)