|
|
@ -1576,6 +1576,10 @@ func DeleteRepository(doer *User, uid, repoID int64) error { |
|
|
|
releaseAttachments = append(releaseAttachments, attachments[i].LocalPath()) |
|
|
|
} |
|
|
|
|
|
|
|
if _, err = sess.Exec("UPDATE `user` SET num_stars=num_stars-1 WHERE id IN (SELECT `uid` FROM `star` WHERE repo_id = ?)", repo.ID); err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
if err = deleteBeans(sess, |
|
|
|
&Access{RepoID: repo.ID}, |
|
|
|
&Action{RepoID: repo.ID}, |
|
|
@ -2341,3 +2345,38 @@ func updateRepositoryCols(e Engine, repo *Repository, cols ...string) error { |
|
|
|
func UpdateRepositoryCols(repo *Repository, cols ...string) error { |
|
|
|
return updateRepositoryCols(x, repo, cols...) |
|
|
|
} |
|
|
|
|
|
|
|
// DoctorUserStarNum recalculate Stars number for all user
|
|
|
|
func DoctorUserStarNum() (err error) { |
|
|
|
const batchSize = 100 |
|
|
|
sess := x.NewSession() |
|
|
|
defer sess.Close() |
|
|
|
|
|
|
|
for start := 0; ; start += batchSize { |
|
|
|
users := make([]User, 0, batchSize) |
|
|
|
if err = sess.Limit(batchSize, start).Where("type = ?", 0).Cols("id").Find(&users); err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
if len(users) == 0 { |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
|
if err = sess.Begin(); err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
for _, user := range users { |
|
|
|
if _, err = sess.Exec("UPDATE `user` SET num_stars=(SELECT COUNT(*) FROM `star` WHERE uid=?) WHERE id=?", user.ID, user.ID); err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if err = sess.Commit(); err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log.Debug("recalculate Stars number for all user finished") |
|
|
|
|
|
|
|
return |
|
|
|
} |