summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/attachment.go2
-rw-r--r--models/branches.go6
-rw-r--r--models/gpg_key.go4
-rw-r--r--models/issue.go8
-rw-r--r--models/issue_comment.go4
-rw-r--r--models/issue_label.go8
-rw-r--r--models/issue_milestone.go6
-rw-r--r--models/issue_user.go2
-rw-r--r--models/lfs.go4
-rw-r--r--models/migrations/migrations.go17
-rw-r--r--models/migrations/v13.go2
-rw-r--r--models/models.go7
-rw-r--r--models/org.go4
-rw-r--r--models/org_team.go12
-rw-r--r--models/pull.go4
-rw-r--r--models/repo.go12
-rw-r--r--models/repo_collaboration.go6
-rw-r--r--models/repo_editor.go2
-rw-r--r--models/ssh_key.go8
-rw-r--r--models/user.go6
-rw-r--r--models/user_follow.go4
-rw-r--r--models/user_mail.go4
-rw-r--r--models/webhook.go2
23 files changed, 60 insertions, 74 deletions
diff --git a/models/attachment.go b/models/attachment.go
index d800a47109..3b3521bf60 100644
--- a/models/attachment.go
+++ b/models/attachment.go
@@ -48,7 +48,7 @@ func (a *Attachment) AfterSet(colName string, _ xorm.Cell) {
// IncreaseDownloadCount is update download count + 1
func (a *Attachment) IncreaseDownloadCount() error {
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
// Update download count.
if _, err := sess.Exec("UPDATE `attachment` SET download_count=download_count+1 WHERE id=?", a.ID); err != nil {
diff --git a/models/branches.go b/models/branches.go
index a71c0e9622..6115f9c687 100644
--- a/models/branches.go
+++ b/models/branches.go
@@ -95,7 +95,7 @@ func (repo *Repository) AddProtectedBranch(branchName string, canPush bool) erro
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -126,7 +126,7 @@ func (repo *Repository) ChangeProtectedBranch(id int64, canPush bool) error {
ProtectedBranch.CanPush = canPush
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -146,7 +146,7 @@ func (repo *Repository) DeleteProtectedBranch(id int64) (err error) {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
diff --git a/models/gpg_key.go b/models/gpg_key.go
index 5763ef8403..d39cc54ce6 100644
--- a/models/gpg_key.go
+++ b/models/gpg_key.go
@@ -127,7 +127,7 @@ func AddGPGKey(ownerID int64, content string) (*GPGKey, error) {
//Get DB session
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return nil, err
}
@@ -267,7 +267,7 @@ func DeleteGPGKey(doer *User, id int64) (err error) {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
diff --git a/models/issue.go b/models/issue.go
index d4d0a5a2ff..b5553b7c82 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -406,7 +406,7 @@ func (issue *Issue) clearLabels(e *xorm.Session, doer *User) (err error) {
// Triggers appropriate WebHooks, if any.
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
}
@@ -470,7 +470,7 @@ func (ts labelSorter) Swap(i, j int) {
// Triggers appropriate WebHooks, if any.
func (issue *Issue) ReplaceLabels(labels []*Label, doer *User) (err error) {
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -598,7 +598,7 @@ func (issue *Issue) changeStatus(e *xorm.Session, doer *User, repo *Repository,
// 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
}
@@ -899,7 +899,7 @@ func newIssue(e *xorm.Session, doer *User, opts NewIssueOptions) (err error) {
// NewIssue creates new issue with labels 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
}
diff --git a/models/issue_comment.go b/models/issue_comment.go
index ead3f1bed3..2da70decff 100644
--- a/models/issue_comment.go
+++ b/models/issue_comment.go
@@ -502,7 +502,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
}
@@ -620,7 +620,7 @@ func UpdateComment(c *Comment) error {
// DeleteComment deletes the comment
func DeleteComment(comment *Comment) error {
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}
diff --git a/models/issue_label.go b/models/issue_label.go
index 67e0ac77b5..19bf01c6c7 100644
--- a/models/issue_label.go
+++ b/models/issue_label.go
@@ -223,7 +223,7 @@ func DeleteLabel(repoID, labelID int64) error {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -298,7 +298,7 @@ func NewIssueLabel(issue *Issue, label *Label, doer *User) (err error) {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -327,7 +327,7 @@ func newIssueLabels(e *xorm.Session, issue *Issue, labels []*Label, doer *User)
// NewIssueLabels creates a list of issue-label relations.
func NewIssueLabels(issue *Issue, labels []*Label, doer *User) (err error) {
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -375,7 +375,7 @@ func deleteIssueLabel(e *xorm.Session, issue *Issue, label *Label, doer *User) (
// DeleteIssueLabel deletes issue-label relation.
func DeleteIssueLabel(issue *Issue, label *Label, doer *User) (err error) {
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
diff --git a/models/issue_milestone.go b/models/issue_milestone.go
index cfd2ce1707..d12c309b87 100644
--- a/models/issue_milestone.go
+++ b/models/issue_milestone.go
@@ -104,7 +104,7 @@ func (m *Milestone) APIFormat() *api.Milestone {
// 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
}
@@ -215,7 +215,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
}
@@ -330,7 +330,7 @@ func DeleteMilestoneByRepoID(repoID, id int64) error {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
diff --git a/models/issue_user.go b/models/issue_user.go
index 024a3cccd9..11d47dd0a6 100644
--- a/models/issue_user.go
+++ b/models/issue_user.go
@@ -69,7 +69,7 @@ func updateIssueUserByAssignee(e Engine, 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
}
diff --git a/models/lfs.go b/models/lfs.go
index 99b8138ab7..f908cae1f2 100644
--- a/models/lfs.go
+++ b/models/lfs.go
@@ -56,7 +56,7 @@ func NewLFSMetaObject(m *LFSMetaObject) (*LFSMetaObject, error) {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return nil, err
}
@@ -94,7 +94,7 @@ func RemoveLFSMetaObjectByOid(oid string) error {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index 2a54c497c1..99fd012480 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -167,13 +167,6 @@ Please try to upgrade to a lower version (>= v0.6.0) first, then upgrade to curr
return nil
}
-func sessionRelease(sess *xorm.Session) {
- if !sess.IsCommitedOrRollbacked {
- sess.Rollback()
- }
- sess.Close()
-}
-
func fixLocaleFileLoadPanic(_ *xorm.Engine) error {
cfg, err := ini.Load(setting.CustomConf)
if err != nil {
@@ -214,7 +207,7 @@ func trimCommitActionAppURLPrefix(x *xorm.Engine) error {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -287,7 +280,7 @@ func issueToIssueLabel(x *xorm.Engine) error {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -330,7 +323,7 @@ func attachmentRefactor(x *xorm.Engine) error {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -408,7 +401,7 @@ func renamePullRequestFields(x *xorm.Engine) (err error) {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -492,7 +485,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
}
diff --git a/models/migrations/v13.go b/models/migrations/v13.go
index c9a50a992e..f81271f981 100644
--- a/models/migrations/v13.go
+++ b/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
}
diff --git a/models/models.go b/models/models.go
index 02a782cde3..6a8fbfe624 100644
--- a/models/models.go
+++ b/models/models.go
@@ -49,13 +49,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{}
diff --git a/models/org.go b/models/org.go
index 5c2d89a78d..b4cbabcb53 100644
--- a/models/org.go
+++ b/models/org.go
@@ -127,7 +127,7 @@ func CreateOrganization(org, owner *User) (err error) {
org.Type = UserTypeOrganization
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -481,7 +481,7 @@ func RemoveOrgUser(orgID, userID int64) error {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}
diff --git a/models/org_team.go b/models/org_team.go
index 5c97a7032e..a7a1ba85d6 100644
--- a/models/org_team.go
+++ b/models/org_team.go
@@ -119,7 +119,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
}
@@ -180,7 +180,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
}
@@ -309,7 +309,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
}
@@ -354,7 +354,7 @@ func DeleteTeam(t *Team) error {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}
@@ -482,7 +482,7 @@ func AddTeamMember(team *Team, userID int64) error {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}
@@ -584,7 +584,7 @@ func removeTeamMember(e Engine, team *Team, userID int64) error {
// RemoveTeamMember removes member from given team of given organization.
func RemoveTeamMember(team *Team, userID int64) error {
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}
diff --git a/models/pull.go b/models/pull.go
index b5b63bebf1..882ee1b220 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -406,7 +406,7 @@ func (pr *PullRequest) setMerged() (err error) {
pr.HasMerged = true
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -602,7 +602,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
}
diff --git a/models/repo.go b/models/repo.go
index f8fef47ebe..8d97138420 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -1271,7 +1271,7 @@ func CreateRepository(u *User, opts CreateRepoOptions) (_ *Repository, err error
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return nil, err
}
@@ -1355,7 +1355,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)
}
@@ -1580,7 +1580,7 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
// UpdateRepository updates a repository
func UpdateRepository(repo *Repository, visibilityChanged bool) (err error) {
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -1625,7 +1625,7 @@ func DeleteRepository(uid, repoID int64) error {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -2240,7 +2240,7 @@ func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Reposit
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return nil, err
}
@@ -2284,7 +2284,7 @@ func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Reposit
// Copy LFS meta objects in new session
sess2 := x.NewSession()
- defer sessionRelease(sess2)
+ defer sess2.Close()
if err = sess2.Begin(); err != nil {
return nil, err
}
diff --git a/models/repo_collaboration.go b/models/repo_collaboration.go
index 39df5b9efa..791f022a3f 100644
--- a/models/repo_collaboration.go
+++ b/models/repo_collaboration.go
@@ -46,7 +46,7 @@ func (repo *Repository) AddCollaborator(u *User) error {
collaboration.Mode = AccessModeWrite
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -136,7 +136,7 @@ func (repo *Repository) ChangeCollaborationAccessMode(uid int64, mode AccessMode
collaboration.Mode = mode
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -161,7 +161,7 @@ func (repo *Repository) DeleteCollaboration(uid int64) (err error) {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
diff --git a/models/repo_editor.go b/models/repo_editor.go
index 40898dd4c2..720e071625 100644
--- a/models/repo_editor.go
+++ b/models/repo_editor.go
@@ -401,7 +401,7 @@ func DeleteUploads(uploads ...*Upload) (err error) {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
diff --git a/models/ssh_key.go b/models/ssh_key.go
index 38b172d2ed..947b2dabfd 100644
--- a/models/ssh_key.go
+++ b/models/ssh_key.go
@@ -430,7 +430,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
}
@@ -535,7 +535,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
}
@@ -732,7 +732,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
}
@@ -812,7 +812,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
}
diff --git a/models/user.go b/models/user.go
index 8d8afdfdb8..6484c8cf69 100644
--- a/models/user.go
+++ b/models/user.go
@@ -436,7 +436,7 @@ func (u *User) UploadAvatar(data []byte) error {
m := resize.Resize(avatar.AvatarSize, avatar.AvatarSize, img, resize.NearestNeighbor)
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -715,7 +715,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
}
@@ -1033,7 +1033,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
}
diff --git a/models/user_follow.go b/models/user_follow.go
index 2d64d05473..4bde71cb91 100644
--- a/models/user_follow.go
+++ b/models/user_follow.go
@@ -24,7 +24,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
}
@@ -50,7 +50,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
}
diff --git a/models/user_mail.go b/models/user_mail.go
index 4ccf08e9d9..285ba74f61 100644
--- a/models/user_mail.go
+++ b/models/user_mail.go
@@ -127,7 +127,7 @@ func (email *EmailAddress) Activate() error {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
@@ -208,7 +208,7 @@ func MakeEmailPrimary(email *EmailAddress) error {
}
sess := x.NewSession()
- defer sessionRelease(sess)
+ defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}
diff --git a/models/webhook.go b/models/webhook.go
index 5cb2e13a6d..b7e687a461 100644
--- a/models/webhook.go
+++ b/models/webhook.go
@@ -267,7 +267,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
}