aboutsummaryrefslogtreecommitdiff
path: root/internal/db/repo.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/repo.go')
-rw-r--r--internal/db/repo.go26
1 files changed, 20 insertions, 6 deletions
diff --git a/internal/db/repo.go b/internal/db/repo.go
index 8abe47ed..896c39b8 100644
--- a/internal/db/repo.go
+++ b/internal/db/repo.go
@@ -34,6 +34,7 @@ import (
"gogs.io/gogs/internal/avatar"
"gogs.io/gogs/internal/conf"
dberrors "gogs.io/gogs/internal/db/errors"
+ "gogs.io/gogs/internal/dbutil"
"gogs.io/gogs/internal/errutil"
"gogs.io/gogs/internal/markup"
"gogs.io/gogs/internal/osutil"
@@ -1112,11 +1113,9 @@ func createRepository(e *xorm.Session, doer, owner *User, repo *Repository) (err
return err
}
- owner.NumRepos++
- // Remember visibility preference.
- owner.LastRepoVisibility = repo.IsPrivate
- if err = updateUser(e, owner); err != nil {
- return fmt.Errorf("updateUser: %v", err)
+ _, err = e.Exec(dbutil.Quote("UPDATE %s SET num_repos = num_repos + 1 WHERE id = ?", "user"), owner.ID)
+ if err != nil {
+ return errors.Wrap(err, "increase owned repository count")
}
// Give access to all members in owner team.
@@ -1222,8 +1221,17 @@ func CreateRepository(doer, owner *User, opts CreateRepoOptionsLegacy) (_ *Repos
return nil, fmt.Errorf("CreateRepository 'git update-server-info': %s", stderr)
}
}
+ if err = sess.Commit(); err != nil {
+ return nil, err
+ }
- return repo, sess.Commit()
+ // Remember visibility preference
+ err = Users.Update(context.TODO(), owner.ID, UpdateUserOptions{LastRepoVisibility: &repo.IsPrivate})
+ if err != nil {
+ return nil, errors.Wrap(err, "update user")
+ }
+
+ return repo, nil
}
func countRepositories(userID int64, private bool) int64 {
@@ -2544,6 +2552,12 @@ func ForkRepository(doer, owner *User, baseRepo *Repository, name, desc string)
return nil, fmt.Errorf("Commit: %v", err)
}
+ // Remember visibility preference
+ err = Users.Update(context.TODO(), owner.ID, UpdateUserOptions{LastRepoVisibility: &repo.IsPrivate})
+ if err != nil {
+ return nil, errors.Wrap(err, "update user")
+ }
+
if err = repo.UpdateSize(); err != nil {
log.Error("UpdateSize [repo_id: %d]: %v", repo.ID, err)
}