mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-28 14:43:52 +03:00
fix repository count of user is messed up
This commit is contained in:
parent
9b9e5f0290
commit
d01f688257
5 changed files with 39 additions and 22 deletions
|
@ -649,8 +649,13 @@ func createRepository(e *xorm.Session, u *User, repo *Repository) (err error) {
|
|||
|
||||
if _, err = e.Insert(repo); err != nil {
|
||||
return err
|
||||
} else if _, err = e.Exec("UPDATE `user` SET num_repos=num_repos+1 WHERE id=?", u.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
u.NumRepos++
|
||||
// Remember visibility preference.
|
||||
u.LastRepoVisibility = repo.IsPrivate
|
||||
if err = updateUser(e, u); err != nil {
|
||||
return fmt.Errorf("updateUser: %v", err)
|
||||
}
|
||||
|
||||
// Give access to all members in owner team.
|
||||
|
@ -1279,7 +1284,7 @@ func CheckRepoStats() {
|
|||
|
||||
log.Trace("Doing: CheckRepoStats")
|
||||
|
||||
// ***** START: Watch *****
|
||||
// ***** START: Repository.NumWatches *****
|
||||
results, err := x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_watches!=(SELECT COUNT(*) FROM `watch` WHERE repo_id=repo.id)")
|
||||
if err != nil {
|
||||
log.Error(4, "Select repository check 'watch': %v", err)
|
||||
|
@ -1293,9 +1298,9 @@ func CheckRepoStats() {
|
|||
log.Error(4, "Update repository check 'watch'[%d]: %v", repoID, err)
|
||||
}
|
||||
}
|
||||
// ***** END: Watch *****
|
||||
// ***** END: Repository.NumWatches *****
|
||||
|
||||
// ***** START: Star *****
|
||||
// ***** START: Repository.NumStars *****
|
||||
results, err = x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_stars!=(SELECT COUNT(*) FROM `star` WHERE repo_id=repo.id)")
|
||||
if err != nil {
|
||||
log.Error(4, "Select repository check 'star': %v", err)
|
||||
|
@ -1309,9 +1314,9 @@ func CheckRepoStats() {
|
|||
log.Error(4, "Update repository check 'star'[%d]: %v", repoID, err)
|
||||
}
|
||||
}
|
||||
// ***** END: Star *****
|
||||
// ***** END: Repository.NumStars *****
|
||||
|
||||
// ***** START: Label *****
|
||||
// ***** START: Label.NumIssues *****
|
||||
results, err = x.Query("SELECT label.id FROM `label` WHERE label.num_issues!=(SELECT COUNT(*) FROM `issue_label` WHERE label_id=label.id)")
|
||||
if err != nil {
|
||||
log.Error(4, "Select label check 'num_issues': %v", err)
|
||||
|
@ -1325,7 +1330,23 @@ func CheckRepoStats() {
|
|||
log.Error(4, "Update label check 'num_issues'[%d]: %v", labelID, err)
|
||||
}
|
||||
}
|
||||
// ***** END: Label *****
|
||||
// ***** END: Label.NumIssues *****
|
||||
|
||||
// ***** START: User.NumRepos *****
|
||||
results, err = x.Query("SELECT `user`.id FROM `user` WHERE `user`.num_repos!=(SELECT COUNT(*) FROM `repository` WHERE owner_id=`user`.id)")
|
||||
if err != nil {
|
||||
log.Error(4, "Select user check 'num_repos': %v", err)
|
||||
return
|
||||
}
|
||||
for _, user := range results {
|
||||
userID := com.StrTo(user["id"]).MustInt64()
|
||||
log.Trace("Updating user count 'num_repos': %d", userID)
|
||||
_, err = x.Exec("UPDATE `user` SET num_repos=(SELECT COUNT(*) FROM `repository` WHERE owner_id=?) WHERE id=?", userID, userID)
|
||||
if err != nil {
|
||||
log.Error(4, "Update user check 'num_repos'[%d]: %v", userID, err)
|
||||
}
|
||||
}
|
||||
// ***** END: User.NumRepos *****
|
||||
}
|
||||
|
||||
// _________ .__ .__ ___. __ .__
|
||||
|
|
|
@ -479,10 +479,9 @@ func ChangeUserName(u *User, newUserName string) (err error) {
|
|||
return os.Rename(UserPath(u.LowerName), UserPath(newUserName))
|
||||
}
|
||||
|
||||
// UpdateUser updates user's information.
|
||||
func UpdateUser(u *User) error {
|
||||
func updateUser(e Engine, u *User) error {
|
||||
u.Email = strings.ToLower(u.Email)
|
||||
has, err := x.Where("id!=?", u.Id).And("type=?", u.Type).And("email=?", u.Email).Get(new(User))
|
||||
has, err := e.Where("id!=?", u.Id).And("type=?", u.Type).And("email=?", u.Email).Get(new(User))
|
||||
if err != nil {
|
||||
return err
|
||||
} else if has {
|
||||
|
@ -507,10 +506,15 @@ func UpdateUser(u *User) error {
|
|||
u.Avatar = avatar.HashEmail(u.AvatarEmail)
|
||||
|
||||
u.FullName = base.Sanitizer.Sanitize(u.FullName)
|
||||
_, err = x.Id(u.Id).AllCols().Update(u)
|
||||
_, err = e.Id(u.Id).AllCols().Update(u)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateUser updates user's information.
|
||||
func UpdateUser(u *User) error {
|
||||
return updateUser(x, u)
|
||||
}
|
||||
|
||||
// DeleteBeans deletes all given beans, beans should contain delete conditions.
|
||||
func DeleteBeans(e Engine, beans ...interface{}) (err error) {
|
||||
for i := range beans {
|
||||
|
|
2
public/css/gogs.min.css
vendored
2
public/css/gogs.min.css
vendored
File diff suppressed because one or more lines are too long
|
@ -232,7 +232,7 @@
|
|||
color: #bd2c00;
|
||||
}
|
||||
&.octicon-primitive-dot {
|
||||
font-size: 35px;
|
||||
font-size: 30px;
|
||||
color: #6cc644;
|
||||
}
|
||||
&.octicon-bookmark {
|
||||
|
|
|
@ -120,10 +120,6 @@ func CreatePost(ctx *middleware.Context, form auth.CreateRepoForm) {
|
|||
AutoInit: form.AutoInit,
|
||||
})
|
||||
if err == nil {
|
||||
// Remember visibility preference.
|
||||
ctx.User.LastRepoVisibility = repo.IsPrivate
|
||||
models.UpdateUser(ctx.User)
|
||||
|
||||
log.Trace("Repository created: %s/%s", ctxUser.Name, repo.Name)
|
||||
ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name)
|
||||
return
|
||||
|
@ -190,10 +186,6 @@ func MigratePost(ctx *middleware.Context, form auth.MigrateRepoForm) {
|
|||
|
||||
repo, err := models.MigrateRepository(ctxUser, form.RepoName, form.Description, form.Private, form.Mirror, remoteAddr)
|
||||
if err == nil {
|
||||
// Remember visibility preference.
|
||||
ctx.User.LastRepoVisibility = repo.IsPrivate
|
||||
models.UpdateUser(ctx.User)
|
||||
|
||||
log.Trace("Repository migrated: %s/%s", ctxUser.Name, form.RepoName)
|
||||
ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + form.RepoName)
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue