Fix #19513 This PR introduce a new db method `InTransaction(context.Context)`, and also builtin check on `db.TxContext` and `db.WithTx`. There is also a new method `db.AutoTx` has been introduced but could be used by other PRs. `WithTx` will always open a new transaction, if a transaction exist in context, return an error. `AutoTx` will try to open a new transaction if no transaction exist in context. That means it will always enter a transaction if there is no error. Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: 6543 <6543@obermui.de>tags/v1.19.0-rc0
@@ -572,7 +572,7 @@ func NotifyWatchers(actions ...*Action) error { | |||
// NotifyWatchersActions creates batch of actions for every watcher. | |||
func NotifyWatchersActions(acts []*Action) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -142,7 +142,7 @@ func CountNotifications(opts *FindNotificationOptions) (int64, error) { | |||
// CreateRepoTransferNotification creates notification for the user a repository was transferred to | |||
func CreateRepoTransferNotification(doer, newOwner *user_model.User, repo *repo_model.Repository) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -185,7 +185,7 @@ func CreateRepoTransferNotification(doer, newOwner *user_model.User, repo *repo_ | |||
// for each watcher, or updates it if already exists | |||
// receiverID > 0 just send to receiver, else send to all watcher | |||
func CreateOrUpdateIssueNotifications(issueID, commentID, notificationAuthorID, receiverID int64) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -234,7 +234,7 @@ func DeleteGPGKey(doer *user_model.User, id int64) (err error) { | |||
return ErrGPGKeyAccessDenied{doer.ID, key.ID} | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -73,7 +73,7 @@ func AddGPGKey(ownerID int64, content, token, signature string) ([]*GPGKey, erro | |||
return nil, err | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} |
@@ -31,7 +31,7 @@ import ( | |||
// VerifyGPGKey marks a GPG key as verified | |||
func VerifyGPGKey(ownerID int64, keyID, token, signature string) (string, error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return "", err | |||
} |
@@ -100,7 +100,7 @@ func AddPublicKey(ownerID int64, name, content string, authSourceID int64) (*Pub | |||
return nil, err | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} | |||
@@ -321,7 +321,7 @@ func PublicKeyIsExternallyManaged(id int64) (bool, error) { | |||
// deleteKeysMarkedForDeletion returns true if ssh keys needs update | |||
func deleteKeysMarkedForDeletion(keys []string) (bool, error) { | |||
// Start session | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return false, err | |||
} |
@@ -126,7 +126,7 @@ func AddDeployKey(repoID int64, name, content string, readOnly bool) (*DeployKey | |||
accessMode = perm.AccessModeWrite | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} |
@@ -26,7 +26,7 @@ import ( | |||
// AddPrincipalKey adds new principal to database and authorized_principals file. | |||
func AddPrincipalKey(ownerID int64, content string, authSourceID int64) (*PublicKey, error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} |
@@ -15,7 +15,7 @@ import ( | |||
// VerifySSHKey marks a SSH key as verified | |||
func VerifySSHKey(ownerID int64, fingerprint, token, signature string) (string, error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return "", err | |||
} |
@@ -201,7 +201,7 @@ type UpdateOAuth2ApplicationOptions struct { | |||
// UpdateOAuth2Application updates an oauth2 application | |||
func UpdateOAuth2Application(opts UpdateOAuth2ApplicationOptions) (*OAuth2Application, error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} | |||
@@ -265,7 +265,7 @@ func deleteOAuth2Application(ctx context.Context, id, userid int64) error { | |||
// DeleteOAuth2Application deletes the application with the given id and the grants and auth codes related to it. It checks if the userid was the creator of the app. | |||
func DeleteOAuth2Application(id, userid int64) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -37,7 +37,7 @@ func ReadSession(key string) (*Session, error) { | |||
Key: key, | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} | |||
@@ -73,7 +73,7 @@ func DestroySession(key string) error { | |||
// RegenerateSession regenerates a session from the old id | |||
func RegenerateSession(oldKey, newKey string) (*Session, error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} |
@@ -97,7 +97,7 @@ func saveEmailHash(email string) string { | |||
Hash: emailHash, | |||
} | |||
// OK we're going to open a session just because I think that that might hide away any problems with postgres reporting errors | |||
if err := db.WithTx(func(ctx context.Context) error { | |||
if err := db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
has, err := db.GetEngine(ctx).Where("email = ? AND hash = ?", emailHash.Email, emailHash.Hash).Get(new(EmailHash)) | |||
if has || err != nil { | |||
// Seriously we don't care about any DB problems just return the lowerEmail - we expect the transaction to fail most of the time |
@@ -8,6 +8,7 @@ import ( | |||
"context" | |||
"database/sql" | |||
"xorm.io/xorm" | |||
"xorm.io/xorm/schemas" | |||
) | |||
@@ -86,7 +87,11 @@ type Committer interface { | |||
} | |||
// TxContext represents a transaction Context | |||
func TxContext() (*Context, Committer, error) { | |||
func TxContext(parentCtx context.Context) (*Context, Committer, error) { | |||
if InTransaction(parentCtx) { | |||
return nil, nil, ErrAlreadyInTransaction | |||
} | |||
sess := x.NewSession() | |||
if err := sess.Begin(); err != nil { | |||
sess.Close() | |||
@@ -97,14 +102,24 @@ func TxContext() (*Context, Committer, error) { | |||
} | |||
// WithTx represents executing database operations on a transaction | |||
// you can optionally change the context to a parent one | |||
func WithTx(f func(ctx context.Context) error, stdCtx ...context.Context) error { | |||
parentCtx := DefaultContext | |||
if len(stdCtx) != 0 && stdCtx[0] != nil { | |||
// TODO: make sure parent context has no open session | |||
parentCtx = stdCtx[0] | |||
// This function will always open a new transaction, if a transaction exist in parentCtx return an error. | |||
func WithTx(parentCtx context.Context, f func(ctx context.Context) error) error { | |||
if InTransaction(parentCtx) { | |||
return ErrAlreadyInTransaction | |||
} | |||
return txWithNoCheck(parentCtx, f) | |||
} | |||
// AutoTx represents executing database operations on a transaction, if the transaction exist, | |||
// this function will reuse it otherwise will create a new one and close it when finished. | |||
func AutoTx(parentCtx context.Context, f func(ctx context.Context) error) error { | |||
if InTransaction(parentCtx) { | |||
return f(newContext(parentCtx, GetEngine(parentCtx), true)) | |||
} | |||
return txWithNoCheck(parentCtx, f) | |||
} | |||
func txWithNoCheck(parentCtx context.Context, f func(ctx context.Context) error) error { | |||
sess := x.NewSession() | |||
defer sess.Close() | |||
if err := sess.Begin(); err != nil { | |||
@@ -180,3 +195,28 @@ func EstimateCount(ctx context.Context, bean interface{}) (int64, error) { | |||
} | |||
return rows, err | |||
} | |||
// InTransaction returns true if the engine is in a transaction otherwise return false | |||
func InTransaction(ctx context.Context) bool { | |||
var e Engine | |||
if engined, ok := ctx.(Engined); ok { | |||
e = engined.Engine() | |||
} else { | |||
enginedInterface := ctx.Value(enginedContextKey) | |||
if enginedInterface != nil { | |||
e = enginedInterface.(Engined).Engine() | |||
} | |||
} | |||
if e == nil { | |||
return false | |||
} | |||
switch t := e.(type) { | |||
case *xorm.Engine: | |||
return false | |||
case *xorm.Session: | |||
return t.IsInTx() | |||
default: | |||
return false | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
// Copyright 2022 The Gitea Authors. All rights reserved. | |||
// Use of this source code is governed by a MIT-style | |||
// license that can be found in the LICENSE file. | |||
package db_test | |||
import ( | |||
"context" | |||
"testing" | |||
"code.gitea.io/gitea/models/db" | |||
"code.gitea.io/gitea/models/unittest" | |||
"github.com/stretchr/testify/assert" | |||
) | |||
func TestInTransaction(t *testing.T) { | |||
assert.NoError(t, unittest.PrepareTestDatabase()) | |||
assert.False(t, db.InTransaction(db.DefaultContext)) | |||
assert.NoError(t, db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
assert.True(t, db.InTransaction(ctx)) | |||
return nil | |||
})) | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
assert.NoError(t, err) | |||
defer committer.Close() | |||
assert.True(t, db.InTransaction(ctx)) | |||
assert.Error(t, db.WithTx(ctx, func(ctx context.Context) error { | |||
assert.True(t, db.InTransaction(ctx)) | |||
return nil | |||
})) | |||
} |
@@ -5,11 +5,14 @@ | |||
package db | |||
import ( | |||
"errors" | |||
"fmt" | |||
"code.gitea.io/gitea/modules/util" | |||
) | |||
var ErrAlreadyInTransaction = errors.New("database connection has already been in a transaction") | |||
// ErrCancelled represents an error due to context cancellation | |||
type ErrCancelled struct { | |||
Message string |
@@ -59,7 +59,7 @@ func TestSyncMaxResourceIndex(t *testing.T) { | |||
assert.EqualValues(t, 62, maxIndex) | |||
// commit transaction | |||
err = db.WithTx(func(ctx context.Context) error { | |||
err = db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
err = db.SyncMaxResourceIndex(ctx, "test_index", 10, 73) | |||
assert.NoError(t, err) | |||
maxIndex, err = getCurrentResourceIndex(ctx, "test_index", 10) | |||
@@ -73,7 +73,7 @@ func TestSyncMaxResourceIndex(t *testing.T) { | |||
assert.EqualValues(t, 73, maxIndex) | |||
// rollback transaction | |||
err = db.WithTx(func(ctx context.Context) error { | |||
err = db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
err = db.SyncMaxResourceIndex(ctx, "test_index", 10, 84) | |||
maxIndex, err = getCurrentResourceIndex(ctx, "test_index", 10) | |||
assert.NoError(t, err) | |||
@@ -102,7 +102,7 @@ func TestGetNextResourceIndex(t *testing.T) { | |||
assert.EqualValues(t, 2, maxIndex) | |||
// commit transaction | |||
err = db.WithTx(func(ctx context.Context) error { | |||
err = db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
maxIndex, err = db.GetNextResourceIndex(ctx, "test_index", 20) | |||
assert.NoError(t, err) | |||
assert.EqualValues(t, 3, maxIndex) | |||
@@ -114,7 +114,7 @@ func TestGetNextResourceIndex(t *testing.T) { | |||
assert.EqualValues(t, 3, maxIndex) | |||
// rollback transaction | |||
err = db.WithTx(func(ctx context.Context) error { | |||
err = db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
maxIndex, err = db.GetNextResourceIndex(ctx, "test_index", 20) | |||
assert.NoError(t, err) | |||
assert.EqualValues(t, 4, maxIndex) |
@@ -544,7 +544,7 @@ func FindRenamedBranch(repoID int64, from string) (branch *RenamedBranch, exist | |||
// RenameBranch rename a branch | |||
func RenameBranch(repo *repo_model.Repository, from, to string, gitAction func(isDefault bool) error) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -102,7 +102,7 @@ func TestRenameBranch(t *testing.T) { | |||
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) | |||
_isDefault := false | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
defer committer.Close() | |||
assert.NoError(t, err) | |||
assert.NoError(t, git_model.UpdateProtectBranch(ctx, repo1, &git_model.ProtectedBranch{ |
@@ -94,7 +94,7 @@ func GetNextCommitStatusIndex(repoID int64, sha string) (int64, error) { | |||
// getNextCommitStatusIndex return the next index | |||
func getNextCommitStatusIndex(repoID int64, sha string) (int64, error) { | |||
ctx, commiter, err := db.TxContext() | |||
ctx, commiter, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return 0, err | |||
} | |||
@@ -297,7 +297,7 @@ func NewCommitStatus(opts NewCommitStatusOptions) error { | |||
return fmt.Errorf("generate commit status index failed: %w", err) | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %w", opts.Repo.ID, opts.Creator.ID, opts.SHA, err) | |||
} |
@@ -137,7 +137,7 @@ var ErrLFSObjectNotExist = db.ErrNotExist{Resource: "LFS Meta object"} | |||
func NewLFSMetaObject(m *LFSMetaObject) (*LFSMetaObject, error) { | |||
var err error | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} | |||
@@ -185,7 +185,7 @@ func RemoveLFSMetaObjectByOid(repoID int64, oid string) (int64, error) { | |||
return 0, ErrLFSObjectNotExist | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return 0, err | |||
} | |||
@@ -242,7 +242,7 @@ func LFSObjectIsAssociated(oid string) (bool, error) { | |||
// LFSAutoAssociate auto associates accessible LFSMetaObjects | |||
func LFSAutoAssociate(metas []*LFSMetaObject, user *user_model.User, repoID int64) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -44,7 +44,7 @@ func cleanPath(p string) string { | |||
// CreateLFSLock creates a new lock. | |||
func CreateLFSLock(repo *repo_model.Repository, lock *LFSLock) (*LFSLock, error) { | |||
dbCtx, committer, err := db.TxContext() | |||
dbCtx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} | |||
@@ -137,7 +137,7 @@ func CountLFSLockByRepoID(repoID int64) (int64, error) { | |||
// DeleteLFSLockByID deletes a lock by given ID. | |||
func DeleteLFSLockByID(id int64, repo *repo_model.Repository, u *user_model.User, force bool) (*LFSLock, error) { | |||
dbCtx, committer, err := db.TxContext() | |||
dbCtx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} |
@@ -64,7 +64,7 @@ func IsUserAssignedToIssue(ctx context.Context, issue *Issue, user *user_model.U | |||
// ToggleIssueAssignee changes a user between assigned and not assigned for this issue, and make issue comment for it. | |||
func ToggleIssueAssignee(issue *Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *Comment, err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return false, nil, err | |||
} |
@@ -565,7 +565,7 @@ func (c *Comment) LoadAttachments() error { | |||
// UpdateAttachments update attachments by UUIDs for the comment | |||
func (c *Comment) UpdateAttachments(uuids []string) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -1003,7 +1003,7 @@ type CreateCommentOptions struct { | |||
// CreateComment creates comment of issue or commit. | |||
func CreateComment(opts *CreateCommentOptions) (comment *Comment, err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} | |||
@@ -1135,7 +1135,7 @@ func CountComments(opts *FindCommentsOptions) (int64, error) { | |||
// UpdateComment updates information of comment. | |||
func UpdateComment(c *Comment, doer *user_model.User) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -129,7 +129,7 @@ const ( | |||
// CreateIssueDependency creates a new dependency for an issue | |||
func CreateIssueDependency(user *user_model.User, issue, dep *Issue) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -170,7 +170,7 @@ func CreateIssueDependency(user *user_model.User, issue, dep *Issue) error { | |||
// RemoveIssueDependency removes a dependency from an issue | |||
func RemoveIssueDependency(user *user_model.User, issue, dep *Issue, depType DependencyType) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -540,7 +540,7 @@ func clearIssueLabels(ctx context.Context, issue *Issue, doer *user_model.User) | |||
// ClearIssueLabels removes all issue labels as the given user. | |||
// Triggers appropriate WebHooks, if any. | |||
func ClearIssueLabels(issue *Issue, doer *user_model.User) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -588,7 +588,7 @@ func (ts labelSorter) Swap(i, j int) { | |||
// ReplaceIssueLabels removes all current labels and add new labels to the issue. | |||
// Triggers appropriate WebHooks, if any. | |||
func ReplaceIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -760,7 +760,7 @@ func ChangeIssueStatus(ctx context.Context, issue *Issue, doer *user_model.User, | |||
// ChangeIssueTitle changes the title of this issue, as the given user. | |||
func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -794,7 +794,7 @@ func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err | |||
// ChangeIssueRef changes the branch of this issue, as the given user. | |||
func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -844,7 +844,7 @@ func AddDeletePRBranchComment(ctx context.Context, doer *user_model.User, repo * | |||
// UpdateIssueAttachments update attachments by UUIDs for the issue | |||
func UpdateIssueAttachments(issueID int64, uuids []string) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -864,7 +864,7 @@ func UpdateIssueAttachments(issueID int64, uuids []string) (err error) { | |||
// ChangeIssueContent changes issue content, as the given user. | |||
func ChangeIssueContent(issue *Issue, doer *user_model.User, content string) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -1069,7 +1069,7 @@ func NewIssueWithIndex(ctx context.Context, doer *user_model.User, opts NewIssue | |||
// NewIssue creates new issue with labels for repository. | |||
func NewIssue(repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -1986,7 +1986,7 @@ func SearchIssueIDsByKeyword(ctx context.Context, kw string, repoIDs []int64, li | |||
// If the issue status is changed a statusChangeComment is returned | |||
// similarly if the title is changed the titleChanged bool is set to true | |||
func UpdateIssueByAPI(issue *Issue, doer *user_model.User) (statusChangeComment *Comment, titleChanged bool, err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, false, err | |||
} | |||
@@ -2044,7 +2044,7 @@ func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *us | |||
if issue.DeadlineUnix == deadlineUnix { | |||
return nil | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -2436,7 +2436,7 @@ func CountOrphanedIssues() (int64, error) { | |||
// DeleteOrphanedIssues delete issues without a repo | |||
func DeleteOrphanedIssues() error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -9,7 +9,7 @@ import "code.gitea.io/gitea/models/db" | |||
// RecalculateIssueIndexForRepo create issue_index for repo if not exist and | |||
// update it based on highest index of existing issues assigned to a repo | |||
func RecalculateIssueIndexForRepo(repoID int64) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -40,7 +40,7 @@ func updateIssueLock(opts *IssueLockOptions, lock bool) error { | |||
commentType = CommentTypeUnlock | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -110,7 +110,7 @@ func LoadIssuesFromBoardList(bs project_model.BoardList) (map[int64]IssueList, e | |||
// ChangeProjectAssign changes the project associated with an issue | |||
func ChangeProjectAssign(issue *Issue, doer *user_model.User, newProjectID int64) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -166,7 +166,7 @@ func addUpdateIssueProject(ctx context.Context, issue *Issue, doer *user_model.U | |||
// MoveIssueAcrossProjectBoards move a card from one board to another | |||
func MoveIssueAcrossProjectBoards(issue *Issue, board *project_model.Board) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -131,7 +131,7 @@ func testCreateIssue(t *testing.T, repo, doer int64, title, content string, ispu | |||
r := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repo}) | |||
d := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: doer}) | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
assert.NoError(t, err) | |||
defer committer.Close() | |||
@@ -174,7 +174,7 @@ func testCreateComment(t *testing.T, repo, doer, issue int64, content string) *i | |||
i := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: issue}) | |||
c := &issues_model.Comment{Type: issues_model.CommentTypeComment, PosterID: doer, Poster: d, IssueID: issue, Issue: i, Content: content} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
assert.NoError(t, err) | |||
defer committer.Close() | |||
err = db.Insert(ctx, c) |
@@ -232,7 +232,7 @@ func NewLabel(ctx context.Context, label *Label) error { | |||
// NewLabels creates new labels | |||
func NewLabels(labels ...*Label) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -267,7 +267,7 @@ func DeleteLabel(id, labelID int64) error { | |||
return err | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -627,7 +627,7 @@ func NewIssueLabel(issue *Issue, label *Label, doer *user_model.User) (err error | |||
return nil | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -676,7 +676,7 @@ func newIssueLabels(ctx context.Context, issue *Issue, labels []*Label, doer *us | |||
// NewIssueLabels creates a list of issue-label relations. | |||
func NewIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -370,7 +370,7 @@ func TestDeleteIssueLabel(t *testing.T) { | |||
} | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
defer committer.Close() | |||
assert.NoError(t, err) | |||
assert.NoError(t, issues_model.DeleteIssueLabel(ctx, issue, label, doer)) |
@@ -111,7 +111,7 @@ func (m *Milestone) State() api.StateType { | |||
// NewMilestone creates new milestone of repository. | |||
func NewMilestone(m *Milestone) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -161,7 +161,7 @@ func GetMilestoneByRepoIDANDName(repoID int64, name string) (*Milestone, error) | |||
// UpdateMilestone updates information of given milestone. | |||
func UpdateMilestone(m *Milestone, oldIsClosed bool) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -219,7 +219,7 @@ func UpdateMilestoneCounters(ctx context.Context, id int64) error { | |||
// ChangeMilestoneStatusByRepoIDAndID changes a milestone open/closed status if the milestone ID is in the repo. | |||
func ChangeMilestoneStatusByRepoIDAndID(repoID, milestoneID int64, isClosed bool) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -246,7 +246,7 @@ func ChangeMilestoneStatusByRepoIDAndID(repoID, milestoneID int64, isClosed bool | |||
// ChangeMilestoneStatus changes the milestone open/closed status. | |||
func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -290,7 +290,7 @@ func DeleteMilestoneByRepoID(repoID, id int64) error { | |||
return err | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -368,7 +368,7 @@ func (pr *PullRequest) getReviewedByLines(writer io.Writer) error { | |||
return nil | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -498,7 +498,7 @@ func (pr *PullRequest) SetMerged(ctx context.Context) (bool, error) { | |||
// NewPullRequest creates new pull request with labels for repository. | |||
func NewPullRequest(outerCtx context.Context, repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string, pr *PullRequest) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(outerCtx) | |||
if err != nil { | |||
return err | |||
} |
@@ -224,7 +224,7 @@ func CreateReaction(opts *ReactionOptions) (*Reaction, error) { | |||
return nil, ErrForbiddenIssueReaction{opts.Type} | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} |
@@ -374,7 +374,7 @@ func IsContentEmptyErr(err error) bool { | |||
// SubmitReview creates a review out of the existing pending review or creates a new one if no pending review exist | |||
func SubmitReview(doer *user_model.User, issue *Issue, reviewType ReviewType, content, commitID string, stale bool, attachmentUUIDs []string) (*Review, *Comment, error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, nil, err | |||
} | |||
@@ -622,7 +622,7 @@ func DismissReview(review *Review, isDismiss bool) (err error) { | |||
// InsertReviews inserts review and review comments | |||
func InsertReviews(reviews []*Review) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -664,7 +664,7 @@ func InsertReviews(reviews []*Review) error { | |||
// AddReviewRequest add a review request from one reviewer | |||
func AddReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Comment, error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} | |||
@@ -719,7 +719,7 @@ func AddReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Comment, | |||
// RemoveReviewRequest remove a review request from one reviewer | |||
func RemoveReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Comment, error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} | |||
@@ -772,7 +772,7 @@ func RemoveReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Commen | |||
// AddTeamReviewRequest add a review request from one team | |||
func AddTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *user_model.User) (*Comment, error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} | |||
@@ -831,7 +831,7 @@ func AddTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *user_ | |||
// RemoveTeamReviewRequest remove a review request from one team | |||
func RemoveTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *user_model.User) (*Comment, error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} | |||
@@ -949,7 +949,7 @@ func CanMarkConversation(issue *Issue, doer *user_model.User) (permResult bool, | |||
// DeleteReview delete a review and it's code comments | |||
func DeleteReview(r *Review) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -261,7 +261,7 @@ func CreateIssueStopwatch(ctx context.Context, user *user_model.User, issue *Iss | |||
// CancelStopwatch removes the given stopwatch and logs it into issue's timeline. | |||
func CancelStopwatch(user *user_model.User, issue *Issue) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -149,7 +149,7 @@ func GetTrackedSeconds(ctx context.Context, opts FindTrackedTimesOptions) (track | |||
// AddTime will add the given time (in seconds) to the issue | |||
func AddTime(user *user_model.User, issue *Issue, amount int64, created time.Time) (*TrackedTime, error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} | |||
@@ -220,7 +220,7 @@ func TotalTimes(options *FindTrackedTimesOptions) (map[*user_model.User]string, | |||
// DeleteIssueUserTimes deletes times for issue | |||
func DeleteIssueUserTimes(issue *Issue, user *user_model.User) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -257,7 +257,7 @@ func DeleteIssueUserTimes(issue *Issue, user *user_model.User) error { | |||
// DeleteTime delete a specific Time | |||
func DeleteTime(t *TrackedTime) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -20,7 +20,7 @@ func InsertMilestones(ms ...*issues_model.Milestone) (err error) { | |||
return nil | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -42,7 +42,7 @@ func InsertMilestones(ms ...*issues_model.Milestone) (err error) { | |||
// InsertIssues insert issues to database | |||
func InsertIssues(issues ...*issues_model.Issue) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -105,7 +105,7 @@ func InsertIssueComments(comments []*issues_model.Comment) error { | |||
issueIDs.Add(comment.IssueID) | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -137,7 +137,7 @@ func InsertIssueComments(comments []*issues_model.Comment) error { | |||
// InsertPullRequests inserted pull requests | |||
func InsertPullRequests(prs ...*issues_model.PullRequest) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -157,7 +157,7 @@ func InsertPullRequests(prs ...*issues_model.PullRequest) error { | |||
// InsertReleases migrates release | |||
func InsertReleases(rels ...*repo_model.Release) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -99,7 +99,7 @@ func removeOrgUser(ctx context.Context, orgID, userID int64) error { | |||
// RemoveOrgUser removes user from given organization. | |||
func RemoveOrgUser(orgID, userID int64) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -76,7 +76,7 @@ func addAllRepositories(ctx context.Context, t *organization.Team) error { | |||
// AddAllRepositories adds all repositories to the team | |||
func AddAllRepositories(t *organization.Team) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -95,7 +95,7 @@ func RemoveAllRepositories(t *organization.Team) (err error) { | |||
return nil | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -219,7 +219,7 @@ func RemoveRepository(t *organization.Team, repoID int64) error { | |||
return err | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -263,7 +263,7 @@ func NewTeam(t *organization.Team) (err error) { | |||
return organization.ErrTeamAlreadyExist{OrgID: t.OrgID, Name: t.LowerName} | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -308,7 +308,7 @@ func UpdateTeam(t *organization.Team, authChanged, includeAllChanged bool) (err | |||
t.Description = t.Description[:255] | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -375,7 +375,7 @@ func UpdateTeam(t *organization.Team, authChanged, includeAllChanged bool) (err | |||
// DeleteTeam deletes given team. | |||
// It's caller's responsibility to assign organization ID. | |||
func DeleteTeam(t *organization.Team) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -460,7 +460,7 @@ func AddTeamMember(team *organization.Team, userID int64) error { | |||
return err | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -598,7 +598,7 @@ func removeTeamMember(ctx context.Context, team *organization.Team, userID int64 | |||
// RemoveTeamMember removes member from given team of given organization. | |||
func RemoveTeamMember(team *organization.Team, userID int64) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -277,7 +277,7 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) { | |||
org.NumMembers = 1 | |||
org.Type = user_model.UserTypeOrganization | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -564,7 +564,7 @@ func AddOrgUser(orgID, uid int64) error { | |||
return err | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -32,7 +32,7 @@ func getUnitsByTeamID(ctx context.Context, teamID int64) (units []*TeamUnit, err | |||
// UpdateTeamUnits updates a teams's units | |||
func UpdateTeamUnits(team *Team, units []TeamUnit) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -133,7 +133,7 @@ func NewBoard(board *Board) error { | |||
// DeleteBoardByID removes all issues references to the project board. | |||
func DeleteBoardByID(boardID int64) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -78,7 +78,7 @@ func (p *Project) NumOpenIssues() int { | |||
// MoveIssuesOnProjectBoard moves or keeps issues in a column and sorts them inside that column | |||
func MoveIssuesOnProjectBoard(board *Board, sortedIssueIDs map[int64]int64) error { | |||
return db.WithTx(func(ctx context.Context) error { | |||
return db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
sess := db.GetEngine(ctx) | |||
issueIDs := make([]int64, 0, len(sortedIssueIDs)) |
@@ -180,7 +180,7 @@ func NewProject(p *Project) error { | |||
return errors.New("project type is not valid") | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -248,7 +248,7 @@ func updateRepositoryProjectCount(ctx context.Context, repoID int64) error { | |||
// ChangeProjectStatusByRepoIDAndID toggles a project between opened and closed | |||
func ChangeProjectStatusByRepoIDAndID(repoID, projectID int64, isClosed bool) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -272,7 +272,7 @@ func ChangeProjectStatusByRepoIDAndID(repoID, projectID int64, isClosed bool) er | |||
// ChangeProjectStatus toggle a project between opened and closed | |||
func ChangeProjectStatus(p *Project, isClosed bool) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -301,7 +301,7 @@ func changeProjectStatus(ctx context.Context, p *Project, isClosed bool) error { | |||
// DeleteProjectByID deletes a project from a repository. | |||
func DeleteProjectByID(id int64) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -45,7 +45,7 @@ func Init() error { | |||
// DeleteRepository deletes a repository for a user or organization. | |||
// make sure if you call this func to close open sessions (sqlite will otherwise get a deadlock) | |||
func DeleteRepository(doer *user_model.User, uid, repoID int64) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -569,7 +569,7 @@ func UpdateRepoStats(ctx context.Context, id int64) error { | |||
} | |||
func updateUserStarNumbers(users []user_model.User) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -138,7 +138,7 @@ func ChangeCollaborationAccessModeCtx(ctx context.Context, repo *Repository, uid | |||
// ChangeCollaborationAccessMode sets new access mode for the collaboration. | |||
func ChangeCollaborationAccessMode(repo *Repository, uid int64, mode perm.AccessMode) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -110,7 +110,7 @@ func GetTopLanguageStats(repo *Repository, limit int) (LanguageStatList, error) | |||
// UpdateLanguageStats updates the language statistics for repository | |||
func UpdateLanguageStats(repo *Repository, commitID string, stats map[string]int64) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -182,7 +182,7 @@ func UpdateLanguageStats(repo *Repository, commitID string, stats map[string]int | |||
// CopyLanguageStat Copy originalRepo language stat information to destRepo (use for forked repo) | |||
func CopyLanguageStat(originalRepo, destRepo *Repository) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -241,7 +241,7 @@ func UpdateRepoUnit(unit *RepoUnit) error { | |||
// UpdateRepositoryUnits updates a repository's units | |||
func UpdateRepositoryUnits(repo *Repository, units []RepoUnit, deleteUnitTypes []unit.Type) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -26,7 +26,7 @@ func init() { | |||
// StarRepo or unstar repository. | |||
func StarRepo(userID, repoID int64, star bool) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -231,7 +231,7 @@ func GetRepoTopicByName(ctx context.Context, repoID int64, topicName string) (*T | |||
// AddTopic adds a topic name to a repository (if it does not already have it) | |||
func AddTopic(repoID int64, topicName string) (*Topic, error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} | |||
@@ -293,7 +293,7 @@ func SaveTopics(repoID int64, topicNames ...string) error { | |||
return err | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -21,7 +21,7 @@ func UpdateRepositoryOwnerNames(ownerID int64, ownerName string) error { | |||
if ownerID == 0 { | |||
return nil | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -172,7 +172,7 @@ func ChangeRepositoryName(doer *user_model.User, repo *Repository, newRepoName s | |||
} | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -121,7 +121,7 @@ func DeleteUploads(uploads ...*Upload) (err error) { | |||
return nil | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -25,7 +25,7 @@ func DeleteCollaboration(repo *repo_model.Repository, uid int64) (err error) { | |||
UserID: uid, | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -124,7 +124,7 @@ func deleteRepositoryTransfer(ctx context.Context, repoID int64) error { | |||
// CancelRepositoryTransfer marks the repository as ready and remove pending transfer entry, | |||
// thus cancel the transfer process. | |||
func CancelRepositoryTransfer(repo *repo_model.Repository) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -156,7 +156,7 @@ func TestRepositoryReadyForTransfer(status repo_model.RepositoryStatus) error { | |||
// CreatePendingRepositoryTransfer transfer a repo from one owner to a new one. | |||
// it marks the repository transfer as "pending" | |||
func CreatePendingRepositoryTransfer(doer, newOwner *user_model.User, repoID int64, teams []*organization.Team) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -243,7 +243,7 @@ func TransferOwnership(doer *user_model.User, newOwnerName string, repo *repo_mo | |||
} | |||
}() | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -25,7 +25,7 @@ func init() { | |||
// SaveAppStateContent saves the app state item to database | |||
func SaveAppStateContent(key, content string) error { | |||
return db.WithTx(func(ctx context.Context) error { | |||
return db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
eng := db.GetEngine(ctx) | |||
// try to update existing row | |||
res, err := eng.Exec("UPDATE app_state SET revision=revision+1, content=? WHERE id=?", content, key) |
@@ -196,7 +196,7 @@ func SetSetting(setting *Setting) error { | |||
} | |||
func upsertSettingValue(key, value string, version int) error { | |||
return db.WithTx(func(ctx context.Context) error { | |||
return db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
e := db.GetEngine(ctx) | |||
// here we use a general method to do a safe upsert for different databases (and most transaction levels) |
@@ -321,7 +321,7 @@ func DeleteInactiveEmailAddresses(ctx context.Context) error { | |||
// ActivateEmail activates the email address to given user. | |||
func ActivateEmail(email *EmailAddress) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -372,7 +372,7 @@ func MakeEmailPrimary(email *EmailAddress) error { | |||
} | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -510,7 +510,7 @@ func SearchEmails(opts *SearchEmailOptions) ([]*SearchEmailResult, int64, error) | |||
// ActivateUserEmail will change the activated state of an email address, | |||
// either primary or secondary (all in the email_address table) | |||
func ActivateUserEmail(userID int64, email string, activate bool) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -33,7 +33,7 @@ func FollowUser(userID, followID int64) (err error) { | |||
return nil | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -59,7 +59,7 @@ func UnfollowUser(userID, followID int64) (err error) { | |||
return nil | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -163,7 +163,7 @@ func SetUserSetting(userID int64, key, value string) error { | |||
} | |||
func upsertUserSettingValue(userID int64, key, value string) error { | |||
return db.WithTx(func(ctx context.Context) error { | |||
return db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
e := db.GetEngine(ctx) | |||
// here we use a general method to do a safe upsert for different databases (and most transaction levels) |
@@ -695,7 +695,7 @@ func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err e | |||
return err | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -814,7 +814,7 @@ func ChangeUserName(u *User, newUserName string) (err error) { | |||
return err | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -957,7 +957,7 @@ func UpdateUserCols(ctx context.Context, u *User, cols ...string) error { | |||
// UpdateUserSetting updates user's settings. | |||
func UpdateUserSetting(u *User) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -575,7 +575,7 @@ func UpdateWebhookLastStatus(w *Webhook) error { | |||
// deleteWebhook uses argument bean as query condition, | |||
// ID must be specified and do not assign unnecessary fields. | |||
func deleteWebhook(bean *Webhook) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -610,7 +610,7 @@ func DeleteWebhookByOrgID(orgID, id int64) error { | |||
// DeleteDefaultSystemWebhook deletes an admin-configured default or system webhook (where Org and Repo ID both 0) | |||
func DeleteDefaultSystemWebhook(id int64) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -37,7 +37,7 @@ func addCollaborator(ctx context.Context, repo *repo_model.Repository, u *user_m | |||
// AddCollaborator adds new collaboration to a repository with default access mode. | |||
func AddCollaborator(repo *repo_model.Repository, u *user_model.User) error { | |||
return db.WithTx(func(ctx context.Context) error { | |||
return db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
return addCollaborator(ctx, repo, u) | |||
}) | |||
} |
@@ -211,7 +211,7 @@ func CreateRepository(doer, u *user_model.User, opts CreateRepoOptions) (*repo_m | |||
var rollbackRepo *repo_model.Repository | |||
if err := db.WithTx(func(ctx context.Context) error { | |||
if err := db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
if err := CreateRepositoryByExample(ctx, doer, u, repo, false); err != nil { | |||
return err | |||
} |
@@ -173,7 +173,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User, | |||
} | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} | |||
@@ -489,7 +489,7 @@ func pullMirrorReleaseSync(repo *repo_model.Repository, gitRepo *git.Repository) | |||
if err != nil { | |||
return fmt.Errorf("unable to GetTagInfos in pull-mirror Repo[%d:%s/%s]: %w", repo.ID, repo.OwnerName, repo.Name, err) | |||
} | |||
err = db.WithTx(func(ctx context.Context) error { | |||
err = db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
// | |||
// clear out existing releases | |||
// |
@@ -604,7 +604,7 @@ func DeletePackageV2(ctx *context.Context) { | |||
} | |||
func deleteRecipeOrPackage(apictx *context.Context, rref *conan_module.RecipeReference, ignoreRecipeRevision bool, pref *conan_module.PackageReference, ignorePackageRevision bool) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -28,7 +28,7 @@ func saveAsPackageBlob(hsr packages_module.HashedSizeReader, pi *packages_servic | |||
contentStore := packages_module.NewContentStore() | |||
err := db.WithTx(func(ctx context.Context) error { | |||
err := db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
created := true | |||
p := &packages_model.Package{ | |||
OwnerID: pi.Owner.ID, | |||
@@ -117,7 +117,7 @@ func saveAsPackageBlob(hsr packages_module.HashedSizeReader, pi *packages_servic | |||
} | |||
func deleteBlob(ownerID int64, image, digest string) error { | |||
return db.WithTx(func(ctx context.Context) error { | |||
return db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
pfds, err := container_model.GetContainerBlobs(ctx, &container_model.BlobSearchOptions{ | |||
OwnerID: ownerID, | |||
Image: image, |
@@ -77,7 +77,7 @@ func processImageManifest(mci *manifestCreationInfo, buf *packages_module.Hashed | |||
return err | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -190,7 +190,7 @@ func processImageManifestIndex(mci *manifestCreationInfo, buf *packages_module.H | |||
return err | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -355,7 +355,7 @@ func setPackageTag(tag string, pv *packages_model.PackageVersion, deleteOnly boo | |||
return errInvalidTagName | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -13,7 +13,7 @@ import ( | |||
// DeleteDeployKey deletes deploy key from its repository authorized_keys file if needed. | |||
func DeleteDeployKey(doer *user_model.User, id int64) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -26,7 +26,7 @@ func DeletePublicKey(doer *user_model.User, id int64) (err error) { | |||
} | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -25,7 +25,7 @@ func NewAttachment(attach *repo_model.Attachment, file io.Reader) (*repo_model.A | |||
return nil, fmt.Errorf("attachment %s should belong to a repository", attach.Name) | |||
} | |||
err := db.WithTx(func(ctx context.Context) error { | |||
err := db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
attach.UUID = uuid.New().String() | |||
size, err := storage.Attachments.Save(attach.RelativePath(), file, -1) | |||
if err != nil { |
@@ -63,7 +63,7 @@ func addToQueue(pr *issues_model.PullRequest, sha string) { | |||
// ScheduleAutoMerge if schedule is false and no error, pull can be merged directly | |||
func ScheduleAutoMerge(ctx context.Context, doer *user_model.User, pull *issues_model.PullRequest, style repo_model.MergeStyle, message string) (scheduled bool, err error) { | |||
err = db.WithTx(func(ctx context.Context) error { | |||
err = db.WithTx(ctx, func(ctx context.Context) error { | |||
lastCommitStatus, err := pull_service.GetPullRequestCommitStatusState(ctx, pull) | |||
if err != nil { | |||
return err | |||
@@ -81,20 +81,20 @@ func ScheduleAutoMerge(ctx context.Context, doer *user_model.User, pull *issues_ | |||
_, err = issues_model.CreateAutoMergeComment(ctx, issues_model.CommentTypePRScheduledToAutoMerge, pull, doer) | |||
return err | |||
}, ctx) | |||
}) | |||
return scheduled, err | |||
} | |||
// RemoveScheduledAutoMerge cancels a previously scheduled pull request | |||
func RemoveScheduledAutoMerge(ctx context.Context, doer *user_model.User, pull *issues_model.PullRequest) error { | |||
return db.WithTx(func(ctx context.Context) error { | |||
return db.WithTx(ctx, func(ctx context.Context) error { | |||
if err := pull_model.DeleteScheduledAutoMerge(ctx, pull.ID); err != nil { | |||
return err | |||
} | |||
_, err := issues_model.CreateAutoMergeComment(ctx, issues_model.CommentTypePRUnScheduledToAutoMerge, pull, doer) | |||
return err | |||
}, ctx) | |||
}) | |||
} | |||
// MergeScheduledPullRequest merges a previously scheduled pull request when all checks succeeded |
@@ -72,7 +72,7 @@ func UpdateComment(c *issues_model.Comment, doer *user_model.User, oldContent st | |||
// DeleteComment deletes the comment | |||
func DeleteComment(doer *user_model.User, comment *issues_model.Comment) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -209,7 +209,7 @@ func GetRefEndNamesAndURLs(issues []*issues_model.Issue, repoLink string) (map[i | |||
// deleteIssue deletes the issue | |||
func deleteIssue(issue *issues_model.Issue) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -45,7 +45,7 @@ func AddLabels(issue *issues_model.Issue, doer *user_model.User, labels []*issue | |||
// RemoveLabel removes a label from issue by given ID. | |||
func RemoveLabel(issue *issues_model.Issue, doer *user_model.User, label *issues_model.Label) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -65,7 +65,7 @@ func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *is | |||
// ChangeMilestoneAssign changes assignment of milestone for issue. | |||
func ChangeMilestoneAssign(issue *issues_model.Issue, doer *user_model.User, oldMilestoneID int64) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -19,7 +19,7 @@ import ( | |||
// DeleteOrganization completely and permanently deletes everything of organization. | |||
func DeleteOrganization(org *organization.Organization) error { | |||
ctx, commiter, err := db.TxContext() | |||
ctx, commiter, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -22,7 +22,7 @@ func TeamAddRepository(t *organization.Team, repo *repo_model.Repository) (err e | |||
return nil | |||
} | |||
return db.WithTx(func(ctx context.Context) error { | |||
return db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
return models.AddRepository(ctx, t, repo) | |||
}) | |||
} |
@@ -76,7 +76,7 @@ func CreatePackageOrAddFileToExisting(pvci *PackageCreationInfo, pfci *PackageFi | |||
} | |||
func createPackageAndAddFile(pvci *PackageCreationInfo, pfci *PackageFileCreationInfo, allowDuplicate bool) (*packages_model.PackageVersion, *packages_model.PackageFile, error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, nil, err | |||
} | |||
@@ -190,7 +190,7 @@ func createPackageAndVersion(ctx context.Context, pvci *PackageCreationInfo, all | |||
// AddFileToExistingPackage adds a file to an existing package. If the package does not exist, ErrPackageNotExist is returned | |||
func AddFileToExistingPackage(pvi *PackageInfo, pfci *PackageFileCreationInfo) (*packages_model.PackageVersion, *packages_model.PackageFile, error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, nil, err | |||
} | |||
@@ -388,7 +388,7 @@ func RemovePackageVersionByNameAndVersion(doer *user_model.User, pvi *PackageInf | |||
// RemovePackageVersion deletes the package version and all associated files | |||
func RemovePackageVersion(doer *user_model.User, pv *packages_model.PackageVersion) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -444,7 +444,7 @@ func DeletePackageFile(ctx context.Context, pf *packages_model.PackageFile) erro | |||
// Cleanup removes expired package data | |||
func Cleanup(unused context.Context, olderThan time.Duration) error { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -63,7 +63,7 @@ func AddToTaskQueue(pr *issues_model.PullRequest) { | |||
// CheckPullMergable check if the pull mergable based on all conditions (branch protection, merge options, ...) | |||
func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *access_model.Permission, pr *issues_model.PullRequest, manuallMerge, force bool) error { | |||
return db.WithTx(func(ctx context.Context) error { | |||
return db.WithTx(stdCtx, func(ctx context.Context) error { | |||
if pr.HasMerged { | |||
return ErrHasMerged | |||
} | |||
@@ -122,7 +122,7 @@ func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *acce | |||
} | |||
return nil | |||
}, stdCtx) | |||
}) | |||
} | |||
// isSignedIfRequired check if merge will be signed if required |
@@ -828,7 +828,7 @@ func MergedManually(pr *issues_model.PullRequest, doer *user_model.User, baseGit | |||
pullWorkingPool.CheckIn(fmt.Sprint(pr.ID)) | |||
defer pullWorkingPool.CheckOut(fmt.Sprint(pr.ID)) | |||
if err := db.WithTx(func(ctx context.Context) error { | |||
if err := db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
prUnit, err := pr.BaseRepo.GetUnitCtx(ctx, unit.TypePullRequests) | |||
if err != nil { | |||
return err |
@@ -196,7 +196,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod | |||
} | |||
rel.LowerTagName = strings.ToLower(rel.TagName) | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -54,7 +54,7 @@ func AdoptRepository(doer, u *user_model.User, opts repo_module.CreateRepoOption | |||
IsEmpty: !opts.AutoInit, | |||
} | |||
if err := db.WithTx(func(ctx context.Context) error { | |||
if err := db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
repoPath := repo_model.RepoPath(u.Name, repo.Name) | |||
isExist, err := util.IsExist(repoPath) | |||
if err != nil { |
@@ -174,7 +174,7 @@ func (aReq *ArchiveRequest) Await(ctx context.Context) (*repo_model.RepoArchiver | |||
} | |||
func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) { | |||
txCtx, committer, err := db.TxContext() | |||
txCtx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return nil, err | |||
} |
@@ -33,7 +33,7 @@ func UploadAvatar(repo *repo_model.Repository, data []byte) error { | |||
return nil | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -76,7 +76,7 @@ func DeleteAvatar(repo *repo_model.Repository) error { | |||
avatarPath := repo.CustomAvatarRelativePath() | |||
log.Trace("DeleteAvatar[%d]: %s", repo.ID, avatarPath) | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -112,7 +112,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork | |||
panic(panicErr) | |||
}() | |||
err = db.WithTx(func(txCtx context.Context) error { | |||
err = db.WithTx(ctx, func(txCtx context.Context) error { | |||
if err = repo_module.CreateRepositoryByExample(txCtx, doer, owner, repo, false); err != nil { | |||
return err | |||
} | |||
@@ -184,7 +184,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork | |||
// ConvertForkToNormalRepository convert the provided repo from a forked repo to normal repo | |||
func ConvertForkToNormalRepository(repo *repo_model.Repository) error { | |||
err := db.WithTx(func(ctx context.Context) error { | |||
err := db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
repo, err := repo_model.GetRepositoryByIDCtx(ctx, repo.ID) | |||
if err != nil { | |||
return err |
@@ -290,7 +290,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error { | |||
// PushUpdateAddDeleteTags updates a number of added and delete tags | |||
func PushUpdateAddDeleteTags(repo *repo_model.Repository, gitRepo *git.Repository, addTags, delTags []string) error { | |||
return db.WithTx(func(ctx context.Context) error { | |||
return db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
if err := repo_model.PushUpdateDeleteTagsContext(ctx, repo, delTags); err != nil { | |||
return err | |||
} |
@@ -90,7 +90,7 @@ func Init() error { | |||
// UpdateRepository updates a repository | |||
func UpdateRepository(repo *repo_model.Repository, visibilityChanged bool) (err error) { | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |
@@ -48,7 +48,7 @@ func GenerateRepository(doer, owner *user_model.User, templateRepo *repo_model.R | |||
} | |||
var generateRepo *repo_model.Repository | |||
if err = db.WithTx(func(ctx context.Context) error { | |||
if err = db.WithTx(db.DefaultContext, func(ctx context.Context) error { | |||
generateRepo, err = repo_module.GenerateRepository(ctx, doer, owner, templateRepo, opts) | |||
if err != nil { | |||
return err |
@@ -132,7 +132,7 @@ func DeleteUser(ctx context.Context, u *user_model.User, purge bool) error { | |||
} | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} | |||
@@ -235,7 +235,7 @@ func UploadAvatar(u *user_model.User, data []byte) error { | |||
return err | |||
} | |||
ctx, committer, err := db.TxContext() | |||
ctx, committer, err := db.TxContext(db.DefaultContext) | |||
if err != nil { | |||
return err | |||
} |