summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2019-07-17 13:34:13 -0400
committertechknowlogick <techknowlogick@gitea.io>2019-07-17 13:34:13 -0400
commit361607d83109014a8dfd40e97c6f95a0e869dca3 (patch)
tree48660e184f04da7741816b61c9e7648b71dea3f3 /models
parent0e2996caa19892d2adf0720074bcffefe3c7535d (diff)
downloadgitea-361607d83109014a8dfd40e97c6f95a0e869dca3.tar.gz
gitea-361607d83109014a8dfd40e97c6f95a0e869dca3.zip
Update User.NumRepos atomically in createRepository (#7493)
The update call on the user call races if there is more than one repository creation concurrently, leading to incorrect count of repos. Split things in two, so that we call the update for last visibility (which isn't problematic if it races, since it can only ever be best-effort anyway). This way we can atomically increment the count of repos.
Diffstat (limited to 'models')
-rw-r--r--models/repo.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/models/repo.go b/models/repo.go
index fc5f81eb5c..c60488844c 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -1306,13 +1306,17 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
return err
}
- u.NumRepos++
// Remember visibility preference.
u.LastRepoVisibility = repo.IsPrivate
- if err = updateUser(e, u); err != nil {
+ if err = updateUserCols(e, u, "last_repo_visibility"); err != nil {
return fmt.Errorf("updateUser: %v", err)
}
+ if _, err = e.Incr("num_repos").ID(u.ID).Update(new(User)); err != nil {
+ return fmt.Errorf("increment user total_repos: %v", err)
+ }
+ u.NumRepos++
+
// Give access to all members in owner team.
if u.IsOrganization() {
t, err := u.getOwnerTeam(e)