Browse Source

Refactoring: remove sessionRelease()

XORM supports automatic roll back in session Close() already.
pull/4584/head
Unknwon 8 years ago
parent
commit
0e6a6bf880
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 4
      models/comment.go
  2. 12
      models/issue.go
  3. 8
      models/issue_label.go
  4. 2
      models/migrations/migrations.go
  5. 2
      models/migrations/v13.go
  6. 8
      models/milestone.go
  7. 7
      models/models.go
  8. 6
      models/org.go
  9. 12
      models/org_team.go
  10. 4
      models/pull.go
  11. 4
      models/release.go
  12. 8
      models/repo.go
  13. 4
      models/repo_branch.go
  14. 6
      models/repo_collaboration.go
  15. 2
      models/repo_editor.go
  16. 8
      models/ssh_key.go
  17. 10
      models/user.go
  18. 4
      models/user_mail.go
  19. 2
      models/webhook.go

4
models/comment.go

@ -323,7 +323,7 @@ type CreateCommentOptions struct {
// CreateComment creates comment of issue or commit.
func CreateComment(opts *CreateCommentOptions) (comment *Comment, err error) {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return nil, err
}
@ -497,7 +497,7 @@ func DeleteCommentByID(doer *User, id int64) error {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

12
models/issue.go

@ -325,7 +325,7 @@ func (issue *Issue) clearLabels(e *xorm.Session) (err error) {
func (issue *Issue) ClearLabels(doer *User) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -370,7 +370,7 @@ func (issue *Issue) ClearLabels(doer *User) (err error) {
// ReplaceLabels removes all current labels and add new labels to the issue.
func (issue *Issue) ReplaceLabels(labels []*Label) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -455,7 +455,7 @@ func (i *Issue) changeStatus(e *xorm.Session, doer *User, repo *Repository, isCl
// ChangeStatus changes issue status to open or closed.
func (issue *Issue) ChangeStatus(doer *User, repo *Repository, isClosed bool) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -744,7 +744,7 @@ func newIssue(e *xorm.Session, opts NewIssueOptions) (err error) {
// NewIssue creates new issue with labels and attachments for repository.
func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -1062,7 +1062,7 @@ func newIssueUsers(e *xorm.Session, repo *Repository, issue *Issue) error {
// NewIssueUsers adds new issue-user relations for new issue of repository.
func NewIssueUsers(repo *Repository, issue *Issue) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -1391,7 +1391,7 @@ func updateIssueUserByAssignee(e *xorm.Session, issue *Issue) (err error) {
// UpdateIssueUserByAssignee updates issue-user relation for assignee.
func UpdateIssueUserByAssignee(issue *Issue) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

8
models/issue_label.go

@ -216,7 +216,7 @@ func DeleteLabel(repoID, labelID int64) error {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -282,7 +282,7 @@ func NewIssueLabel(issue *Issue, label *Label) (err error) {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -311,7 +311,7 @@ func newIssueLabels(e *xorm.Session, issue *Issue, labels []*Label) (err error)
// NewIssueLabels creates a list of issue-label relations.
func NewIssueLabels(issue *Issue, labels []*Label) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -361,7 +361,7 @@ func deleteIssueLabel(e *xorm.Session, issue *Issue, label *Label) (err error) {
// DeleteIssueLabel deletes issue-label relation.
func DeleteIssueLabel(issue *Issue, label *Label) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

2
models/migrations/migrations.go

@ -153,7 +153,7 @@ func generateOrgRandsAndSalt(x *xorm.Engine) (err error) {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

2
models/migrations/v13.go

@ -23,7 +23,7 @@ func ldapUseSSLToSecurityProtocol(x *xorm.Engine) error {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

8
models/milestone.go

@ -115,7 +115,7 @@ func (m *Milestone) CountIssues(isClosed, includePulls bool) int64 {
// NewMilestone creates new milestone of repository.
func NewMilestone(m *Milestone) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -211,7 +211,7 @@ func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -254,7 +254,7 @@ func changeMilestoneIssueStats(e *xorm.Session, issue *Issue) error {
// for the milestone associated with the given issue.
func ChangeMilestoneIssueStats(issue *Issue) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -378,7 +378,7 @@ func DeleteMilestoneOfRepoByID(repoID, id int64) error {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

7
models/models.go

@ -43,13 +43,6 @@ type Engine interface {
Where(interface{}, ...interface{}) *xorm.Session
}
func sessionRelease(sess *xorm.Session) {
if !sess.IsCommitedOrRollbacked {
sess.Rollback()
}
sess.Close()
}
var (
x *xorm.Engine
tables []interface{}

6
models/org.go

@ -124,7 +124,7 @@ func CreateOrganization(org, owner *User) (err error) {
org.NumMembers = 1
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -208,7 +208,7 @@ func DeleteOrganization(org *User) (err error) {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -405,7 +405,7 @@ func RemoveOrgUser(orgID, userID int64) error {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}

12
models/org_team.go

@ -139,7 +139,7 @@ func (t *Team) AddRepository(repo *Repository) (err error) {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -199,7 +199,7 @@ func (t *Team) RemoveRepository(repoID int64) error {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -321,7 +321,7 @@ func UpdateTeam(t *Team, authChanged bool) (err error) {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -368,7 +368,7 @@ func DeleteTeam(t *Team) error {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -488,7 +488,7 @@ func AddTeamMember(orgID, teamID, userID int64) error {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -592,7 +592,7 @@ func removeTeamMember(e Engine, orgID, teamID, uid int64) error {
// RemoveTeamMember removes member from given team of given organization.
func RemoveTeamMember(orgID, teamID, uid int64) error {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}

4
models/pull.go

@ -192,7 +192,7 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error
}()
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -382,7 +382,7 @@ func (pr *PullRequest) testPatch() (err error) {
// NewPullRequest creates new pull request with labels for repository.
func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []string, pr *PullRequest, patch []byte) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

4
models/release.go

@ -175,7 +175,7 @@ func NewRelease(gitRepo *git.Repository, r *Release, uuids []string) error {
r.LowerTagName = strings.ToLower(r.TagName)
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -289,7 +289,7 @@ func UpdateRelease(doer *User, gitRepo *git.Repository, r *Release, isPublish bo
r.PublisherID = doer.ID
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

8
models/repo.go

@ -1043,7 +1043,7 @@ func CreateRepository(doer, owner *User, opts CreateRepoOptions) (_ *Repository,
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return nil, err
}
@ -1172,7 +1172,7 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return fmt.Errorf("sess.Begin: %v", err)
}
@ -1415,7 +1415,7 @@ func DeleteRepository(uid, repoID int64) error {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -2276,7 +2276,7 @@ func ForkRepository(doer, owner *User, baseRepo *Repository, name, desc string)
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return nil, err
}

4
models/repo_branch.go

@ -119,7 +119,7 @@ func IsBranchOfRepoRequirePullRequest(repoID int64, name string) bool {
// If ID is 0, it creates a new record. Otherwise, updates existing record.
func UpdateProtectBranch(protectBranch *ProtectBranch) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -228,7 +228,7 @@ func UpdateOrgProtectBranch(repo *Repository, protectBranch *ProtectBranch, whit
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

6
models/repo_collaboration.go

@ -67,7 +67,7 @@ func (repo *Repository) AddCollaborator(u *User) error {
collaboration.Mode = ACCESS_MODE_WRITE
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -165,7 +165,7 @@ func (repo *Repository) ChangeCollaborationAccessMode(userID int64, mode AccessM
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -207,7 +207,7 @@ func DeleteCollaboration(repo *Repository, userID int64) (err error) {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

2
models/repo_editor.go

@ -380,7 +380,7 @@ func DeleteUploads(uploads ...*Upload) (err error) {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

8
models/ssh_key.go

@ -417,7 +417,7 @@ func AddPublicKey(ownerID int64, name, content string) (*PublicKey, error) {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return nil, err
}
@ -499,7 +499,7 @@ func DeletePublicKey(doer *User, id int64) (err error) {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -663,7 +663,7 @@ func AddDeployKey(repoID int64, name, content string) (*DeployKey, error) {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return nil, err
}
@ -741,7 +741,7 @@ func DeleteDeployKey(doer *User, id int64) error {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

10
models/user.go

@ -335,7 +335,7 @@ func (u *User) UploadAvatar(data []byte) error {
m := resize.Resize(avatar.AVATAR_SIZE, avatar.AVATAR_SIZE, img, resize.NearestNeighbor)
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -569,7 +569,7 @@ func CreateUser(u *User) (err error) {
u.MaxRepoCreation = -1
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -839,7 +839,7 @@ func deleteUser(e *xorm.Session, u *User) error {
// but issues/comments/pulls will be kept and shown as someone has been deleted.
func DeleteUser(u *User) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -1104,7 +1104,7 @@ func FollowUser(userID, followID int64) (err error) {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -1130,7 +1130,7 @@ func UnfollowUser(userID, followID int64) (err error) {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

4
models/user_mail.go

@ -126,7 +126,7 @@ func (email *EmailAddress) Activate() error {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@ -188,7 +188,7 @@ func MakeEmailPrimary(email *EmailAddress) error {
}
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

2
models/webhook.go

@ -294,7 +294,7 @@ func UpdateWebhook(w *Webhook) error {
// ID must be specified and do not assign unnecessary fields.
func deleteWebhook(bean *Webhook) (err error) {
sess := x.NewSession()
defer sessionRelease(sess)
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

Loading…
Cancel
Save