-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Decrease the num_stars when deleting a repo #11954
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
67d90e7
Decrease the num_stars when deleting a repo
a1012112796 35daf9d
Add migration
a1012112796 8cef62d
Merge branch 'master' into fix_star_num
a1012112796 737b997
use batch
a1012112796 2cc54a6
Merge branch 'master' into fix_star_num
a1012112796 5bdfa3d
Apply suggestions from code review
a1012112796 9c1e588
fix lint
a1012112796 d57c755
Merge branch 'master' into fix_star_num
a1012112796 8eaa0a6
fix lint
a1012112796 b1347b8
fix ci
a1012112796 974c926
fix ci2
a1012112796 c7be7cc
Merge branch 'master' into fix_star_num
a1012112796 8b99408
Merge branch 'master' into fix_star_num
zeripath dc7f9b3
add doctor
a1012112796 c6d39d7
Merge branch 'master' into fix_star_num
a1012112796 b935dba
duplicate code
a1012112796 929c1b8
Merge branch 'master' into fix_star_num
a1012112796 8b6f9b3
fix migration
a1012112796 7b7232a
fix some nits
a1012112796 fedb10a
Merge branch 'master' into fix_star_num
a1012112796 3d8af43
add start
a1012112796 0b1b55e
Merge branch 'master' into fix_star_num
lunny f0699fb
Merge branch 'master' into fix_star_num
lunny 3ecb312
Merge branch 'master' into fix_star_num
a1012112796 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"code.gitea.io/gitea/models" | ||
"code.gitea.io/gitea/modules/log" | ||
"xorm.io/xorm" | ||
) | ||
|
||
func recalculateStars(x *xorm.Engine) (err error) { | ||
// because of issue https://github.com/go-gitea/gitea/issues/11949, | ||
// recalculate Stars number for all users to fully fix it. | ||
|
||
const batchSize = 100 | ||
sess := x.NewSession() | ||
defer sess.Close() | ||
|
||
for start := 0; ; start += batchSize { | ||
userIDs := make([]int64, 0, batchSize) | ||
if err = sess.Table("user").Limit(batchSize, start).Where("type = ?", 0).Cols("id").Find(&userIDs); err != nil { | ||
return err | ||
} | ||
if len(userIDs) == 0 { | ||
break | ||
} | ||
|
||
a1012112796 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var number int64 | ||
|
||
for _, uid := range userIDs { | ||
if number, err = x.Where("uid = ?", uid).Count(new(models.Star)); err != nil { | ||
return | ||
} | ||
|
||
if _, err = x.Exec("UPDATE `user` SET num_stars=? WHERE id = ?", number, uid); err != nil { | ||
return err | ||
} | ||
a1012112796 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
log.Debug("recalculate Stars number for all user finished") | ||
|
||
return sess.Commit() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.