Allow detect whether it's in a database transaction for a context.Context (#21756)

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>
This commit is contained in:
Lunny Xiao 2022-11-13 04:18:50 +08:00 committed by GitHub
parent a0a425a13b
commit 34283a74e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
91 changed files with 252 additions and 176 deletions

View file

@ -572,7 +572,7 @@ func NotifyWatchers(actions ...*Action) error {
// NotifyWatchersActions creates batch of actions for every watcher. // NotifyWatchersActions creates batch of actions for every watcher.
func NotifyWatchersActions(acts []*Action) error { func NotifyWatchersActions(acts []*Action) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -142,7 +142,7 @@ func CountNotifications(opts *FindNotificationOptions) (int64, error) {
// CreateRepoTransferNotification creates notification for the user a repository was transferred to // CreateRepoTransferNotification creates notification for the user a repository was transferred to
func CreateRepoTransferNotification(doer, newOwner *user_model.User, repo *repo_model.Repository) error { 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 { if err != nil {
return err return err
} }
@ -185,7 +185,7 @@ func CreateRepoTransferNotification(doer, newOwner *user_model.User, repo *repo_
// for each watcher, or updates it if already exists // for each watcher, or updates it if already exists
// receiverID > 0 just send to receiver, else send to all watcher // receiverID > 0 just send to receiver, else send to all watcher
func CreateOrUpdateIssueNotifications(issueID, commentID, notificationAuthorID, receiverID int64) error { func CreateOrUpdateIssueNotifications(issueID, commentID, notificationAuthorID, receiverID int64) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -234,7 +234,7 @@ func DeleteGPGKey(doer *user_model.User, id int64) (err error) {
return ErrGPGKeyAccessDenied{doer.ID, key.ID} return ErrGPGKeyAccessDenied{doer.ID, key.ID}
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -73,7 +73,7 @@ func AddGPGKey(ownerID int64, content, token, signature string) ([]*GPGKey, erro
return nil, err return nil, err
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -31,7 +31,7 @@ import (
// VerifyGPGKey marks a GPG key as verified // VerifyGPGKey marks a GPG key as verified
func VerifyGPGKey(ownerID int64, keyID, token, signature string) (string, error) { 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 { if err != nil {
return "", err return "", err
} }

View file

@ -100,7 +100,7 @@ func AddPublicKey(ownerID int64, name, content string, authSourceID int64) (*Pub
return nil, err return nil, err
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -321,7 +321,7 @@ func PublicKeyIsExternallyManaged(id int64) (bool, error) {
// deleteKeysMarkedForDeletion returns true if ssh keys needs update // deleteKeysMarkedForDeletion returns true if ssh keys needs update
func deleteKeysMarkedForDeletion(keys []string) (bool, error) { func deleteKeysMarkedForDeletion(keys []string) (bool, error) {
// Start session // Start session
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return false, err return false, err
} }

View file

@ -126,7 +126,7 @@ func AddDeployKey(repoID int64, name, content string, readOnly bool) (*DeployKey
accessMode = perm.AccessModeWrite accessMode = perm.AccessModeWrite
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -26,7 +26,7 @@ import (
// AddPrincipalKey adds new principal to database and authorized_principals file. // AddPrincipalKey adds new principal to database and authorized_principals file.
func AddPrincipalKey(ownerID int64, content string, authSourceID int64) (*PublicKey, error) { 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 { if err != nil {
return nil, err return nil, err
} }

View file

@ -15,7 +15,7 @@ import (
// VerifySSHKey marks a SSH key as verified // VerifySSHKey marks a SSH key as verified
func VerifySSHKey(ownerID int64, fingerprint, token, signature string) (string, error) { 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 { if err != nil {
return "", err return "", err
} }

View file

@ -201,7 +201,7 @@ type UpdateOAuth2ApplicationOptions struct {
// UpdateOAuth2Application updates an oauth2 application // UpdateOAuth2Application updates an oauth2 application
func UpdateOAuth2Application(opts UpdateOAuth2ApplicationOptions) (*OAuth2Application, error) { func UpdateOAuth2Application(opts UpdateOAuth2ApplicationOptions) (*OAuth2Application, error) {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return nil, err 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. // 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 { func DeleteOAuth2Application(id, userid int64) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -37,7 +37,7 @@ func ReadSession(key string) (*Session, error) {
Key: key, Key: key,
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -73,7 +73,7 @@ func DestroySession(key string) error {
// RegenerateSession regenerates a session from the old id // RegenerateSession regenerates a session from the old id
func RegenerateSession(oldKey, newKey string) (*Session, error) { func RegenerateSession(oldKey, newKey string) (*Session, error) {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -97,7 +97,7 @@ func saveEmailHash(email string) string {
Hash: emailHash, 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 // 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)) has, err := db.GetEngine(ctx).Where("email = ? AND hash = ?", emailHash.Email, emailHash.Hash).Get(new(EmailHash))
if has || err != nil { 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 // Seriously we don't care about any DB problems just return the lowerEmail - we expect the transaction to fail most of the time

View file

@ -8,6 +8,7 @@ import (
"context" "context"
"database/sql" "database/sql"
"xorm.io/xorm"
"xorm.io/xorm/schemas" "xorm.io/xorm/schemas"
) )
@ -86,7 +87,11 @@ type Committer interface {
} }
// TxContext represents a transaction Context // 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() sess := x.NewSession()
if err := sess.Begin(); err != nil { if err := sess.Begin(); err != nil {
sess.Close() sess.Close()
@ -97,14 +102,24 @@ func TxContext() (*Context, Committer, error) {
} }
// WithTx represents executing database operations on a transaction // WithTx represents executing database operations on a transaction
// you can optionally change the context to a parent one // This function will always open a new transaction, if a transaction exist in parentCtx return an error.
func WithTx(f func(ctx context.Context) error, stdCtx ...context.Context) error { func WithTx(parentCtx context.Context, f func(ctx context.Context) error) error {
parentCtx := DefaultContext if InTransaction(parentCtx) {
if len(stdCtx) != 0 && stdCtx[0] != nil { return ErrAlreadyInTransaction
// TODO: make sure parent context has no open session }
parentCtx = stdCtx[0] 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() sess := x.NewSession()
defer sess.Close() defer sess.Close()
if err := sess.Begin(); err != nil { if err := sess.Begin(); err != nil {
@ -180,3 +195,28 @@ func EstimateCount(ctx context.Context, bean interface{}) (int64, error) {
} }
return rows, err 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
}
}

33
models/db/context_test.go Normal file
View file

@ -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
}))
}

View file

@ -5,11 +5,14 @@
package db package db
import ( import (
"errors"
"fmt" "fmt"
"code.gitea.io/gitea/modules/util" "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 // ErrCancelled represents an error due to context cancellation
type ErrCancelled struct { type ErrCancelled struct {
Message string Message string

View file

@ -59,7 +59,7 @@ func TestSyncMaxResourceIndex(t *testing.T) {
assert.EqualValues(t, 62, maxIndex) assert.EqualValues(t, 62, maxIndex)
// commit transaction // 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) err = db.SyncMaxResourceIndex(ctx, "test_index", 10, 73)
assert.NoError(t, err) assert.NoError(t, err)
maxIndex, err = getCurrentResourceIndex(ctx, "test_index", 10) maxIndex, err = getCurrentResourceIndex(ctx, "test_index", 10)
@ -73,7 +73,7 @@ func TestSyncMaxResourceIndex(t *testing.T) {
assert.EqualValues(t, 73, maxIndex) assert.EqualValues(t, 73, maxIndex)
// rollback transaction // 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) err = db.SyncMaxResourceIndex(ctx, "test_index", 10, 84)
maxIndex, err = getCurrentResourceIndex(ctx, "test_index", 10) maxIndex, err = getCurrentResourceIndex(ctx, "test_index", 10)
assert.NoError(t, err) assert.NoError(t, err)
@ -102,7 +102,7 @@ func TestGetNextResourceIndex(t *testing.T) {
assert.EqualValues(t, 2, maxIndex) assert.EqualValues(t, 2, maxIndex)
// commit transaction // 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) maxIndex, err = db.GetNextResourceIndex(ctx, "test_index", 20)
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, 3, maxIndex) assert.EqualValues(t, 3, maxIndex)
@ -114,7 +114,7 @@ func TestGetNextResourceIndex(t *testing.T) {
assert.EqualValues(t, 3, maxIndex) assert.EqualValues(t, 3, maxIndex)
// rollback transaction // 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) maxIndex, err = db.GetNextResourceIndex(ctx, "test_index", 20)
assert.NoError(t, err) assert.NoError(t, err)
assert.EqualValues(t, 4, maxIndex) assert.EqualValues(t, 4, maxIndex)

View file

@ -544,7 +544,7 @@ func FindRenamedBranch(repoID int64, from string) (branch *RenamedBranch, exist
// RenameBranch rename a branch // RenameBranch rename a branch
func RenameBranch(repo *repo_model.Repository, from, to string, gitAction func(isDefault bool) error) (err error) { 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 { if err != nil {
return err return err
} }

View file

@ -102,7 +102,7 @@ func TestRenameBranch(t *testing.T) {
repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
_isDefault := false _isDefault := false
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
defer committer.Close() defer committer.Close()
assert.NoError(t, err) assert.NoError(t, err)
assert.NoError(t, git_model.UpdateProtectBranch(ctx, repo1, &git_model.ProtectedBranch{ assert.NoError(t, git_model.UpdateProtectBranch(ctx, repo1, &git_model.ProtectedBranch{

View file

@ -94,7 +94,7 @@ func GetNextCommitStatusIndex(repoID int64, sha string) (int64, error) {
// getNextCommitStatusIndex return the next index // getNextCommitStatusIndex return the next index
func getNextCommitStatusIndex(repoID int64, sha string) (int64, error) { func getNextCommitStatusIndex(repoID int64, sha string) (int64, error) {
ctx, commiter, err := db.TxContext() ctx, commiter, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -297,7 +297,7 @@ func NewCommitStatus(opts NewCommitStatusOptions) error {
return fmt.Errorf("generate commit status index failed: %w", err) 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 { 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) return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %w", opts.Repo.ID, opts.Creator.ID, opts.SHA, err)
} }

View file

@ -137,7 +137,7 @@ var ErrLFSObjectNotExist = db.ErrNotExist{Resource: "LFS Meta object"}
func NewLFSMetaObject(m *LFSMetaObject) (*LFSMetaObject, error) { func NewLFSMetaObject(m *LFSMetaObject) (*LFSMetaObject, error) {
var err error var err error
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -185,7 +185,7 @@ func RemoveLFSMetaObjectByOid(repoID int64, oid string) (int64, error) {
return 0, ErrLFSObjectNotExist return 0, ErrLFSObjectNotExist
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -242,7 +242,7 @@ func LFSObjectIsAssociated(oid string) (bool, error) {
// LFSAutoAssociate auto associates accessible LFSMetaObjects // LFSAutoAssociate auto associates accessible LFSMetaObjects
func LFSAutoAssociate(metas []*LFSMetaObject, user *user_model.User, repoID int64) error { 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 { if err != nil {
return err return err
} }

View file

@ -44,7 +44,7 @@ func cleanPath(p string) string {
// CreateLFSLock creates a new lock. // CreateLFSLock creates a new lock.
func CreateLFSLock(repo *repo_model.Repository, lock *LFSLock) (*LFSLock, error) { 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 { if err != nil {
return nil, err return nil, err
} }
@ -137,7 +137,7 @@ func CountLFSLockByRepoID(repoID int64) (int64, error) {
// DeleteLFSLockByID deletes a lock by given ID. // DeleteLFSLockByID deletes a lock by given ID.
func DeleteLFSLockByID(id int64, repo *repo_model.Repository, u *user_model.User, force bool) (*LFSLock, error) { 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 { if err != nil {
return nil, err return nil, err
} }

View file

@ -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. // 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) { 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 { if err != nil {
return false, nil, err return false, nil, err
} }

View file

@ -565,7 +565,7 @@ func (c *Comment) LoadAttachments() error {
// UpdateAttachments update attachments by UUIDs for the comment // UpdateAttachments update attachments by UUIDs for the comment
func (c *Comment) UpdateAttachments(uuids []string) error { func (c *Comment) UpdateAttachments(uuids []string) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -1003,7 +1003,7 @@ type CreateCommentOptions struct {
// CreateComment creates comment of issue or commit. // CreateComment creates comment of issue or commit.
func CreateComment(opts *CreateCommentOptions) (comment *Comment, err error) { func CreateComment(opts *CreateCommentOptions) (comment *Comment, err error) {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1135,7 +1135,7 @@ func CountComments(opts *FindCommentsOptions) (int64, error) {
// UpdateComment updates information of comment. // UpdateComment updates information of comment.
func UpdateComment(c *Comment, doer *user_model.User) error { func UpdateComment(c *Comment, doer *user_model.User) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -129,7 +129,7 @@ const (
// CreateIssueDependency creates a new dependency for an issue // CreateIssueDependency creates a new dependency for an issue
func CreateIssueDependency(user *user_model.User, issue, dep *Issue) error { 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 { if err != nil {
return err return err
} }
@ -170,7 +170,7 @@ func CreateIssueDependency(user *user_model.User, issue, dep *Issue) error {
// RemoveIssueDependency removes a dependency from an issue // RemoveIssueDependency removes a dependency from an issue
func RemoveIssueDependency(user *user_model.User, issue, dep *Issue, depType DependencyType) (err error) { 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 { if err != nil {
return err return err
} }

View file

@ -540,7 +540,7 @@ func clearIssueLabels(ctx context.Context, issue *Issue, doer *user_model.User)
// ClearIssueLabels removes all issue labels as the given user. // ClearIssueLabels removes all issue labels as the given user.
// Triggers appropriate WebHooks, if any. // Triggers appropriate WebHooks, if any.
func ClearIssueLabels(issue *Issue, doer *user_model.User) (err error) { 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 { if err != nil {
return err 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. // ReplaceIssueLabels removes all current labels and add new labels to the issue.
// Triggers appropriate WebHooks, if any. // Triggers appropriate WebHooks, if any.
func ReplaceIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (err error) { 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 { if err != nil {
return err 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. // ChangeIssueTitle changes the title of this issue, as the given user.
func ChangeIssueTitle(issue *Issue, doer *user_model.User, oldTitle string) (err error) { 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 { if err != nil {
return err 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. // ChangeIssueRef changes the branch of this issue, as the given user.
func ChangeIssueRef(issue *Issue, doer *user_model.User, oldRef string) (err error) { 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 { if err != nil {
return err return err
} }
@ -844,7 +844,7 @@ func AddDeletePRBranchComment(ctx context.Context, doer *user_model.User, repo *
// UpdateIssueAttachments update attachments by UUIDs for the issue // UpdateIssueAttachments update attachments by UUIDs for the issue
func UpdateIssueAttachments(issueID int64, uuids []string) (err error) { func UpdateIssueAttachments(issueID int64, uuids []string) (err error) {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -864,7 +864,7 @@ func UpdateIssueAttachments(issueID int64, uuids []string) (err error) {
// ChangeIssueContent changes issue content, as the given user. // ChangeIssueContent changes issue content, as the given user.
func ChangeIssueContent(issue *Issue, doer *user_model.User, content string) (err error) { 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 { if err != nil {
return err 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. // NewIssue creates new issue with labels for repository.
func NewIssue(repo *repo_model.Repository, issue *Issue, labelIDs []int64, uuids []string) (err error) { 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 { if err != nil {
return err 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 // If the issue status is changed a statusChangeComment is returned
// similarly if the title is changed the titleChanged bool is set to true // 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) { 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 { if err != nil {
return nil, false, err return nil, false, err
} }
@ -2044,7 +2044,7 @@ func UpdateIssueDeadline(issue *Issue, deadlineUnix timeutil.TimeStamp, doer *us
if issue.DeadlineUnix == deadlineUnix { if issue.DeadlineUnix == deadlineUnix {
return nil return nil
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -2436,7 +2436,7 @@ func CountOrphanedIssues() (int64, error) {
// DeleteOrphanedIssues delete issues without a repo // DeleteOrphanedIssues delete issues without a repo
func DeleteOrphanedIssues() error { func DeleteOrphanedIssues() error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -9,7 +9,7 @@ import "code.gitea.io/gitea/models/db"
// RecalculateIssueIndexForRepo create issue_index for repo if not exist and // RecalculateIssueIndexForRepo create issue_index for repo if not exist and
// update it based on highest index of existing issues assigned to a repo // update it based on highest index of existing issues assigned to a repo
func RecalculateIssueIndexForRepo(repoID int64) error { func RecalculateIssueIndexForRepo(repoID int64) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -40,7 +40,7 @@ func updateIssueLock(opts *IssueLockOptions, lock bool) error {
commentType = CommentTypeUnlock commentType = CommentTypeUnlock
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -110,7 +110,7 @@ func LoadIssuesFromBoardList(bs project_model.BoardList) (map[int64]IssueList, e
// ChangeProjectAssign changes the project associated with an issue // ChangeProjectAssign changes the project associated with an issue
func ChangeProjectAssign(issue *Issue, doer *user_model.User, newProjectID int64) error { 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 { if err != nil {
return err 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 // MoveIssueAcrossProjectBoards move a card from one board to another
func MoveIssueAcrossProjectBoards(issue *Issue, board *project_model.Board) error { func MoveIssueAcrossProjectBoards(issue *Issue, board *project_model.Board) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -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}) r := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repo})
d := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: doer}) 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) assert.NoError(t, err)
defer committer.Close() 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}) 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} 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) assert.NoError(t, err)
defer committer.Close() defer committer.Close()
err = db.Insert(ctx, c) err = db.Insert(ctx, c)

View file

@ -232,7 +232,7 @@ func NewLabel(ctx context.Context, label *Label) error {
// NewLabels creates new labels // NewLabels creates new labels
func NewLabels(labels ...*Label) error { func NewLabels(labels ...*Label) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -267,7 +267,7 @@ func DeleteLabel(id, labelID int64) error {
return err return err
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -627,7 +627,7 @@ func NewIssueLabel(issue *Issue, label *Label, doer *user_model.User) (err error
return nil return nil
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err 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. // NewIssueLabels creates a list of issue-label relations.
func NewIssueLabels(issue *Issue, labels []*Label, doer *user_model.User) (err error) { 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 { if err != nil {
return err return err
} }

View file

@ -370,7 +370,7 @@ func TestDeleteIssueLabel(t *testing.T) {
} }
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
defer committer.Close() defer committer.Close()
assert.NoError(t, err) assert.NoError(t, err)
assert.NoError(t, issues_model.DeleteIssueLabel(ctx, issue, label, doer)) assert.NoError(t, issues_model.DeleteIssueLabel(ctx, issue, label, doer))

View file

@ -111,7 +111,7 @@ func (m *Milestone) State() api.StateType {
// NewMilestone creates new milestone of repository. // NewMilestone creates new milestone of repository.
func NewMilestone(m *Milestone) (err error) { func NewMilestone(m *Milestone) (err error) {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -161,7 +161,7 @@ func GetMilestoneByRepoIDANDName(repoID int64, name string) (*Milestone, error)
// UpdateMilestone updates information of given milestone. // UpdateMilestone updates information of given milestone.
func UpdateMilestone(m *Milestone, oldIsClosed bool) error { func UpdateMilestone(m *Milestone, oldIsClosed bool) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err 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. // ChangeMilestoneStatusByRepoIDAndID changes a milestone open/closed status if the milestone ID is in the repo.
func ChangeMilestoneStatusByRepoIDAndID(repoID, milestoneID int64, isClosed bool) error { func ChangeMilestoneStatusByRepoIDAndID(repoID, milestoneID int64, isClosed bool) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -246,7 +246,7 @@ func ChangeMilestoneStatusByRepoIDAndID(repoID, milestoneID int64, isClosed bool
// ChangeMilestoneStatus changes the milestone open/closed status. // ChangeMilestoneStatus changes the milestone open/closed status.
func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) { func ChangeMilestoneStatus(m *Milestone, isClosed bool) (err error) {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -290,7 +290,7 @@ func DeleteMilestoneByRepoID(repoID, id int64) error {
return err return err
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -368,7 +368,7 @@ func (pr *PullRequest) getReviewedByLines(writer io.Writer) error {
return nil return nil
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -498,7 +498,7 @@ func (pr *PullRequest) SetMerged(ctx context.Context) (bool, error) {
// NewPullRequest creates new pull request with labels for repository. // 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) { 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 { if err != nil {
return err return err
} }

View file

@ -224,7 +224,7 @@ func CreateReaction(opts *ReactionOptions) (*Reaction, error) {
return nil, ErrForbiddenIssueReaction{opts.Type} return nil, ErrForbiddenIssueReaction{opts.Type}
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -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 // 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) { 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 { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -622,7 +622,7 @@ func DismissReview(review *Review, isDismiss bool) (err error) {
// InsertReviews inserts review and review comments // InsertReviews inserts review and review comments
func InsertReviews(reviews []*Review) error { func InsertReviews(reviews []*Review) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -664,7 +664,7 @@ func InsertReviews(reviews []*Review) error {
// AddReviewRequest add a review request from one reviewer // AddReviewRequest add a review request from one reviewer
func AddReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Comment, error) { 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 { if err != nil {
return nil, err 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 // RemoveReviewRequest remove a review request from one reviewer
func RemoveReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Comment, error) { 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 { if err != nil {
return nil, err 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 // AddTeamReviewRequest add a review request from one team
func AddTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *user_model.User) (*Comment, error) { 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 { if err != nil {
return nil, err return nil, err
} }
@ -831,7 +831,7 @@ func AddTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *user_
// RemoveTeamReviewRequest remove a review request from one team // RemoveTeamReviewRequest remove a review request from one team
func RemoveTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *user_model.User) (*Comment, error) { 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 { if err != nil {
return nil, err 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 // DeleteReview delete a review and it's code comments
func DeleteReview(r *Review) error { func DeleteReview(r *Review) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -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. // CancelStopwatch removes the given stopwatch and logs it into issue's timeline.
func CancelStopwatch(user *user_model.User, issue *Issue) error { func CancelStopwatch(user *user_model.User, issue *Issue) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -149,7 +149,7 @@ func GetTrackedSeconds(ctx context.Context, opts FindTrackedTimesOptions) (track
// AddTime will add the given time (in seconds) to the issue // 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) { 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 { if err != nil {
return nil, err return nil, err
} }
@ -220,7 +220,7 @@ func TotalTimes(options *FindTrackedTimesOptions) (map[*user_model.User]string,
// DeleteIssueUserTimes deletes times for issue // DeleteIssueUserTimes deletes times for issue
func DeleteIssueUserTimes(issue *Issue, user *user_model.User) error { func DeleteIssueUserTimes(issue *Issue, user *user_model.User) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -257,7 +257,7 @@ func DeleteIssueUserTimes(issue *Issue, user *user_model.User) error {
// DeleteTime delete a specific Time // DeleteTime delete a specific Time
func DeleteTime(t *TrackedTime) error { func DeleteTime(t *TrackedTime) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -20,7 +20,7 @@ func InsertMilestones(ms ...*issues_model.Milestone) (err error) {
return nil return nil
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -42,7 +42,7 @@ func InsertMilestones(ms ...*issues_model.Milestone) (err error) {
// InsertIssues insert issues to database // InsertIssues insert issues to database
func InsertIssues(issues ...*issues_model.Issue) error { func InsertIssues(issues ...*issues_model.Issue) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -105,7 +105,7 @@ func InsertIssueComments(comments []*issues_model.Comment) error {
issueIDs.Add(comment.IssueID) issueIDs.Add(comment.IssueID)
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -137,7 +137,7 @@ func InsertIssueComments(comments []*issues_model.Comment) error {
// InsertPullRequests inserted pull requests // InsertPullRequests inserted pull requests
func InsertPullRequests(prs ...*issues_model.PullRequest) error { func InsertPullRequests(prs ...*issues_model.PullRequest) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -157,7 +157,7 @@ func InsertPullRequests(prs ...*issues_model.PullRequest) error {
// InsertReleases migrates release // InsertReleases migrates release
func InsertReleases(rels ...*repo_model.Release) error { func InsertReleases(rels ...*repo_model.Release) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -99,7 +99,7 @@ func removeOrgUser(ctx context.Context, orgID, userID int64) error {
// RemoveOrgUser removes user from given organization. // RemoveOrgUser removes user from given organization.
func RemoveOrgUser(orgID, userID int64) error { func RemoveOrgUser(orgID, userID int64) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -76,7 +76,7 @@ func addAllRepositories(ctx context.Context, t *organization.Team) error {
// AddAllRepositories adds all repositories to the team // AddAllRepositories adds all repositories to the team
func AddAllRepositories(t *organization.Team) (err error) { func AddAllRepositories(t *organization.Team) (err error) {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -95,7 +95,7 @@ func RemoveAllRepositories(t *organization.Team) (err error) {
return nil return nil
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -219,7 +219,7 @@ func RemoveRepository(t *organization.Team, repoID int64) error {
return err return err
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -263,7 +263,7 @@ func NewTeam(t *organization.Team) (err error) {
return organization.ErrTeamAlreadyExist{OrgID: t.OrgID, Name: t.LowerName} return organization.ErrTeamAlreadyExist{OrgID: t.OrgID, Name: t.LowerName}
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -308,7 +308,7 @@ func UpdateTeam(t *organization.Team, authChanged, includeAllChanged bool) (err
t.Description = t.Description[:255] t.Description = t.Description[:255]
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -375,7 +375,7 @@ func UpdateTeam(t *organization.Team, authChanged, includeAllChanged bool) (err
// DeleteTeam deletes given team. // DeleteTeam deletes given team.
// It's caller's responsibility to assign organization ID. // It's caller's responsibility to assign organization ID.
func DeleteTeam(t *organization.Team) error { func DeleteTeam(t *organization.Team) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -460,7 +460,7 @@ func AddTeamMember(team *organization.Team, userID int64) error {
return err return err
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err 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. // RemoveTeamMember removes member from given team of given organization.
func RemoveTeamMember(team *organization.Team, userID int64) error { func RemoveTeamMember(team *organization.Team, userID int64) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -277,7 +277,7 @@ func CreateOrganization(org *Organization, owner *user_model.User) (err error) {
org.NumMembers = 1 org.NumMembers = 1
org.Type = user_model.UserTypeOrganization org.Type = user_model.UserTypeOrganization
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -564,7 +564,7 @@ func AddOrgUser(orgID, uid int64) error {
return err return err
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -32,7 +32,7 @@ func getUnitsByTeamID(ctx context.Context, teamID int64) (units []*TeamUnit, err
// UpdateTeamUnits updates a teams's units // UpdateTeamUnits updates a teams's units
func UpdateTeamUnits(team *Team, units []TeamUnit) (err error) { func UpdateTeamUnits(team *Team, units []TeamUnit) (err error) {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -133,7 +133,7 @@ func NewBoard(board *Board) error {
// DeleteBoardByID removes all issues references to the project board. // DeleteBoardByID removes all issues references to the project board.
func DeleteBoardByID(boardID int64) error { func DeleteBoardByID(boardID int64) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -78,7 +78,7 @@ func (p *Project) NumOpenIssues() int {
// MoveIssuesOnProjectBoard moves or keeps issues in a column and sorts them inside that column // MoveIssuesOnProjectBoard moves or keeps issues in a column and sorts them inside that column
func MoveIssuesOnProjectBoard(board *Board, sortedIssueIDs map[int64]int64) error { 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) sess := db.GetEngine(ctx)
issueIDs := make([]int64, 0, len(sortedIssueIDs)) issueIDs := make([]int64, 0, len(sortedIssueIDs))

View file

@ -180,7 +180,7 @@ func NewProject(p *Project) error {
return errors.New("project type is not valid") return errors.New("project type is not valid")
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -248,7 +248,7 @@ func updateRepositoryProjectCount(ctx context.Context, repoID int64) error {
// ChangeProjectStatusByRepoIDAndID toggles a project between opened and closed // ChangeProjectStatusByRepoIDAndID toggles a project between opened and closed
func ChangeProjectStatusByRepoIDAndID(repoID, projectID int64, isClosed bool) error { func ChangeProjectStatusByRepoIDAndID(repoID, projectID int64, isClosed bool) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -272,7 +272,7 @@ func ChangeProjectStatusByRepoIDAndID(repoID, projectID int64, isClosed bool) er
// ChangeProjectStatus toggle a project between opened and closed // ChangeProjectStatus toggle a project between opened and closed
func ChangeProjectStatus(p *Project, isClosed bool) error { func ChangeProjectStatus(p *Project, isClosed bool) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -301,7 +301,7 @@ func changeProjectStatus(ctx context.Context, p *Project, isClosed bool) error {
// DeleteProjectByID deletes a project from a repository. // DeleteProjectByID deletes a project from a repository.
func DeleteProjectByID(id int64) error { func DeleteProjectByID(id int64) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -45,7 +45,7 @@ func Init() error {
// DeleteRepository deletes a repository for a user or organization. // 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) // 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 { 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 { if err != nil {
return err return err
} }
@ -569,7 +569,7 @@ func UpdateRepoStats(ctx context.Context, id int64) error {
} }
func updateUserStarNumbers(users []user_model.User) error { func updateUserStarNumbers(users []user_model.User) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -138,7 +138,7 @@ func ChangeCollaborationAccessModeCtx(ctx context.Context, repo *Repository, uid
// ChangeCollaborationAccessMode sets new access mode for the collaboration. // ChangeCollaborationAccessMode sets new access mode for the collaboration.
func ChangeCollaborationAccessMode(repo *Repository, uid int64, mode perm.AccessMode) error { 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 { if err != nil {
return err return err
} }

View file

@ -110,7 +110,7 @@ func GetTopLanguageStats(repo *Repository, limit int) (LanguageStatList, error)
// UpdateLanguageStats updates the language statistics for repository // UpdateLanguageStats updates the language statistics for repository
func UpdateLanguageStats(repo *Repository, commitID string, stats map[string]int64) error { 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 { if err != nil {
return err 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) // CopyLanguageStat Copy originalRepo language stat information to destRepo (use for forked repo)
func CopyLanguageStat(originalRepo, destRepo *Repository) error { func CopyLanguageStat(originalRepo, destRepo *Repository) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -241,7 +241,7 @@ func UpdateRepoUnit(unit *RepoUnit) error {
// UpdateRepositoryUnits updates a repository's units // UpdateRepositoryUnits updates a repository's units
func UpdateRepositoryUnits(repo *Repository, units []RepoUnit, deleteUnitTypes []unit.Type) (err error) { 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 { if err != nil {
return err return err
} }

View file

@ -26,7 +26,7 @@ func init() {
// StarRepo or unstar repository. // StarRepo or unstar repository.
func StarRepo(userID, repoID int64, star bool) error { func StarRepo(userID, repoID int64, star bool) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -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) // AddTopic adds a topic name to a repository (if it does not already have it)
func AddTopic(repoID int64, topicName string) (*Topic, error) { func AddTopic(repoID int64, topicName string) (*Topic, error) {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -293,7 +293,7 @@ func SaveTopics(repoID int64, topicNames ...string) error {
return err return err
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -21,7 +21,7 @@ func UpdateRepositoryOwnerNames(ownerID int64, ownerName string) error {
if ownerID == 0 { if ownerID == 0 {
return nil return nil
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err 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 { if err != nil {
return err return err
} }

View file

@ -121,7 +121,7 @@ func DeleteUploads(uploads ...*Upload) (err error) {
return nil return nil
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -25,7 +25,7 @@ func DeleteCollaboration(repo *repo_model.Repository, uid int64) (err error) {
UserID: uid, UserID: uid,
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -124,7 +124,7 @@ func deleteRepositoryTransfer(ctx context.Context, repoID int64) error {
// CancelRepositoryTransfer marks the repository as ready and remove pending transfer entry, // CancelRepositoryTransfer marks the repository as ready and remove pending transfer entry,
// thus cancel the transfer process. // thus cancel the transfer process.
func CancelRepositoryTransfer(repo *repo_model.Repository) error { func CancelRepositoryTransfer(repo *repo_model.Repository) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -156,7 +156,7 @@ func TestRepositoryReadyForTransfer(status repo_model.RepositoryStatus) error {
// CreatePendingRepositoryTransfer transfer a repo from one owner to a new one. // CreatePendingRepositoryTransfer transfer a repo from one owner to a new one.
// it marks the repository transfer as "pending" // it marks the repository transfer as "pending"
func CreatePendingRepositoryTransfer(doer, newOwner *user_model.User, repoID int64, teams []*organization.Team) error { 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 { if err != nil {
return err 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 { if err != nil {
return err return err
} }

View file

@ -25,7 +25,7 @@ func init() {
// SaveAppStateContent saves the app state item to database // SaveAppStateContent saves the app state item to database
func SaveAppStateContent(key, content string) error { 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) eng := db.GetEngine(ctx)
// try to update existing row // try to update existing row
res, err := eng.Exec("UPDATE app_state SET revision=revision+1, content=? WHERE id=?", content, key) res, err := eng.Exec("UPDATE app_state SET revision=revision+1, content=? WHERE id=?", content, key)

View file

@ -196,7 +196,7 @@ func SetSetting(setting *Setting) error {
} }
func upsertSettingValue(key, value string, version int) 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) e := db.GetEngine(ctx)
// here we use a general method to do a safe upsert for different databases (and most transaction levels) // here we use a general method to do a safe upsert for different databases (and most transaction levels)

View file

@ -321,7 +321,7 @@ func DeleteInactiveEmailAddresses(ctx context.Context) error {
// ActivateEmail activates the email address to given user. // ActivateEmail activates the email address to given user.
func ActivateEmail(email *EmailAddress) error { func ActivateEmail(email *EmailAddress) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err 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 { if err != nil {
return err return err
} }
@ -510,7 +510,7 @@ func SearchEmails(opts *SearchEmailOptions) ([]*SearchEmailResult, int64, error)
// ActivateUserEmail will change the activated state of an email address, // ActivateUserEmail will change the activated state of an email address,
// either primary or secondary (all in the email_address table) // either primary or secondary (all in the email_address table)
func ActivateUserEmail(userID int64, email string, activate bool) (err error) { 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 { if err != nil {
return err return err
} }

View file

@ -33,7 +33,7 @@ func FollowUser(userID, followID int64) (err error) {
return nil return nil
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -59,7 +59,7 @@ func UnfollowUser(userID, followID int64) (err error) {
return nil return nil
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -163,7 +163,7 @@ func SetUserSetting(userID int64, key, value string) error {
} }
func upsertUserSettingValue(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) e := db.GetEngine(ctx)
// here we use a general method to do a safe upsert for different databases (and most transaction levels) // here we use a general method to do a safe upsert for different databases (and most transaction levels)

View file

@ -695,7 +695,7 @@ func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err e
return err return err
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -814,7 +814,7 @@ func ChangeUserName(u *User, newUserName string) (err error) {
return err return err
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -957,7 +957,7 @@ func UpdateUserCols(ctx context.Context, u *User, cols ...string) error {
// UpdateUserSetting updates user's settings. // UpdateUserSetting updates user's settings.
func UpdateUserSetting(u *User) (err error) { func UpdateUserSetting(u *User) (err error) {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -575,7 +575,7 @@ func UpdateWebhookLastStatus(w *Webhook) error {
// deleteWebhook uses argument bean as query condition, // deleteWebhook uses argument bean as query condition,
// ID must be specified and do not assign unnecessary fields. // ID must be specified and do not assign unnecessary fields.
func deleteWebhook(bean *Webhook) (err error) { func deleteWebhook(bean *Webhook) (err error) {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err 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) // DeleteDefaultSystemWebhook deletes an admin-configured default or system webhook (where Org and Repo ID both 0)
func DeleteDefaultSystemWebhook(id int64) error { func DeleteDefaultSystemWebhook(id int64) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -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. // AddCollaborator adds new collaboration to a repository with default access mode.
func AddCollaborator(repo *repo_model.Repository, u *user_model.User) error { 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) return addCollaborator(ctx, repo, u)
}) })
} }

View file

@ -211,7 +211,7 @@ func CreateRepository(doer, u *user_model.User, opts CreateRepoOptions) (*repo_m
var rollbackRepo *repo_model.Repository 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 { if err := CreateRepositoryByExample(ctx, doer, u, repo, false); err != nil {
return err return err
} }

View file

@ -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 { if err != nil {
return nil, err return nil, err
} }
@ -489,7 +489,7 @@ func pullMirrorReleaseSync(repo *repo_model.Repository, gitRepo *git.Repository)
if err != nil { if err != nil {
return fmt.Errorf("unable to GetTagInfos in pull-mirror Repo[%d:%s/%s]: %w", repo.ID, repo.OwnerName, repo.Name, err) 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 // clear out existing releases
// //

View file

@ -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 { 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 { if err != nil {
return err return err
} }

View file

@ -28,7 +28,7 @@ func saveAsPackageBlob(hsr packages_module.HashedSizeReader, pi *packages_servic
contentStore := packages_module.NewContentStore() contentStore := packages_module.NewContentStore()
err := db.WithTx(func(ctx context.Context) error { err := db.WithTx(db.DefaultContext, func(ctx context.Context) error {
created := true created := true
p := &packages_model.Package{ p := &packages_model.Package{
OwnerID: pi.Owner.ID, 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 { 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{ pfds, err := container_model.GetContainerBlobs(ctx, &container_model.BlobSearchOptions{
OwnerID: ownerID, OwnerID: ownerID,
Image: image, Image: image,

View file

@ -77,7 +77,7 @@ func processImageManifest(mci *manifestCreationInfo, buf *packages_module.Hashed
return err return err
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -190,7 +190,7 @@ func processImageManifestIndex(mci *manifestCreationInfo, buf *packages_module.H
return err return err
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -355,7 +355,7 @@ func setPackageTag(tag string, pv *packages_model.PackageVersion, deleteOnly boo
return errInvalidTagName return errInvalidTagName
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -13,7 +13,7 @@ import (
// DeleteDeployKey deletes deploy key from its repository authorized_keys file if needed. // DeleteDeployKey deletes deploy key from its repository authorized_keys file if needed.
func DeleteDeployKey(doer *user_model.User, id int64) error { func DeleteDeployKey(doer *user_model.User, id int64) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -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 { if err != nil {
return err return err
} }

View file

@ -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) 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() attach.UUID = uuid.New().String()
size, err := storage.Attachments.Save(attach.RelativePath(), file, -1) size, err := storage.Attachments.Save(attach.RelativePath(), file, -1)
if err != nil { if err != nil {

View file

@ -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 // 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) { 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) lastCommitStatus, err := pull_service.GetPullRequestCommitStatusState(ctx, pull)
if err != nil { if err != nil {
return err 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) _, err = issues_model.CreateAutoMergeComment(ctx, issues_model.CommentTypePRScheduledToAutoMerge, pull, doer)
return err return err
}, ctx) })
return scheduled, err return scheduled, err
} }
// RemoveScheduledAutoMerge cancels a previously scheduled pull request // RemoveScheduledAutoMerge cancels a previously scheduled pull request
func RemoveScheduledAutoMerge(ctx context.Context, doer *user_model.User, pull *issues_model.PullRequest) error { 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 { if err := pull_model.DeleteScheduledAutoMerge(ctx, pull.ID); err != nil {
return err return err
} }
_, err := issues_model.CreateAutoMergeComment(ctx, issues_model.CommentTypePRUnScheduledToAutoMerge, pull, doer) _, err := issues_model.CreateAutoMergeComment(ctx, issues_model.CommentTypePRUnScheduledToAutoMerge, pull, doer)
return err return err
}, ctx) })
} }
// MergeScheduledPullRequest merges a previously scheduled pull request when all checks succeeded // MergeScheduledPullRequest merges a previously scheduled pull request when all checks succeeded

View file

@ -72,7 +72,7 @@ func UpdateComment(c *issues_model.Comment, doer *user_model.User, oldContent st
// DeleteComment deletes the comment // DeleteComment deletes the comment
func DeleteComment(doer *user_model.User, comment *issues_model.Comment) error { 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 { if err != nil {
return err return err
} }

View file

@ -209,7 +209,7 @@ func GetRefEndNamesAndURLs(issues []*issues_model.Issue, repoLink string) (map[i
// deleteIssue deletes the issue // deleteIssue deletes the issue
func deleteIssue(issue *issues_model.Issue) error { func deleteIssue(issue *issues_model.Issue) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -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. // RemoveLabel removes a label from issue by given ID.
func RemoveLabel(issue *issues_model.Issue, doer *user_model.User, label *issues_model.Label) error { 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 { if err != nil {
return err return err
} }

View file

@ -65,7 +65,7 @@ func changeMilestoneAssign(ctx context.Context, doer *user_model.User, issue *is
// ChangeMilestoneAssign changes assignment of milestone for issue. // ChangeMilestoneAssign changes assignment of milestone for issue.
func ChangeMilestoneAssign(issue *issues_model.Issue, doer *user_model.User, oldMilestoneID int64) (err error) { 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 { if err != nil {
return err return err
} }

View file

@ -19,7 +19,7 @@ import (
// DeleteOrganization completely and permanently deletes everything of organization. // DeleteOrganization completely and permanently deletes everything of organization.
func DeleteOrganization(org *organization.Organization) error { func DeleteOrganization(org *organization.Organization) error {
ctx, commiter, err := db.TxContext() ctx, commiter, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -22,7 +22,7 @@ func TeamAddRepository(t *organization.Team, repo *repo_model.Repository) (err e
return nil 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) return models.AddRepository(ctx, t, repo)
}) })
} }

View file

@ -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) { 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 { if err != nil {
return nil, nil, err 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 // 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) { 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 { if err != nil {
return nil, nil, err 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 // RemovePackageVersion deletes the package version and all associated files
func RemovePackageVersion(doer *user_model.User, pv *packages_model.PackageVersion) error { 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 { if err != nil {
return err return err
} }
@ -444,7 +444,7 @@ func DeletePackageFile(ctx context.Context, pf *packages_model.PackageFile) erro
// Cleanup removes expired package data // Cleanup removes expired package data
func Cleanup(unused context.Context, olderThan time.Duration) error { func Cleanup(unused context.Context, olderThan time.Duration) error {
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -63,7 +63,7 @@ func AddToTaskQueue(pr *issues_model.PullRequest) {
// CheckPullMergable check if the pull mergable based on all conditions (branch protection, merge options, ...) // 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 { 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 { if pr.HasMerged {
return ErrHasMerged return ErrHasMerged
} }
@ -122,7 +122,7 @@ func CheckPullMergable(stdCtx context.Context, doer *user_model.User, perm *acce
} }
return nil return nil
}, stdCtx) })
} }
// isSignedIfRequired check if merge will be signed if required // isSignedIfRequired check if merge will be signed if required

View file

@ -828,7 +828,7 @@ func MergedManually(pr *issues_model.PullRequest, doer *user_model.User, baseGit
pullWorkingPool.CheckIn(fmt.Sprint(pr.ID)) pullWorkingPool.CheckIn(fmt.Sprint(pr.ID))
defer pullWorkingPool.CheckOut(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) prUnit, err := pr.BaseRepo.GetUnitCtx(ctx, unit.TypePullRequests)
if err != nil { if err != nil {
return err return err

View file

@ -196,7 +196,7 @@ func UpdateRelease(doer *user_model.User, gitRepo *git.Repository, rel *repo_mod
} }
rel.LowerTagName = strings.ToLower(rel.TagName) rel.LowerTagName = strings.ToLower(rel.TagName)
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -54,7 +54,7 @@ func AdoptRepository(doer, u *user_model.User, opts repo_module.CreateRepoOption
IsEmpty: !opts.AutoInit, 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) repoPath := repo_model.RepoPath(u.Name, repo.Name)
isExist, err := util.IsExist(repoPath) isExist, err := util.IsExist(repoPath)
if err != nil { if err != nil {

View file

@ -174,7 +174,7 @@ func (aReq *ArchiveRequest) Await(ctx context.Context) (*repo_model.RepoArchiver
} }
func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) { func doArchive(r *ArchiveRequest) (*repo_model.RepoArchiver, error) {
txCtx, committer, err := db.TxContext() txCtx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -33,7 +33,7 @@ func UploadAvatar(repo *repo_model.Repository, data []byte) error {
return nil return nil
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }
@ -76,7 +76,7 @@ func DeleteAvatar(repo *repo_model.Repository) error {
avatarPath := repo.CustomAvatarRelativePath() avatarPath := repo.CustomAvatarRelativePath()
log.Trace("DeleteAvatar[%d]: %s", repo.ID, avatarPath) log.Trace("DeleteAvatar[%d]: %s", repo.ID, avatarPath)
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }

View file

@ -112,7 +112,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
panic(panicErr) 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 { if err = repo_module.CreateRepositoryByExample(txCtx, doer, owner, repo, false); err != nil {
return err 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 // ConvertForkToNormalRepository convert the provided repo from a forked repo to normal repo
func ConvertForkToNormalRepository(repo *repo_model.Repository) error { 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) repo, err := repo_model.GetRepositoryByIDCtx(ctx, repo.ID)
if err != nil { if err != nil {
return err return err

View file

@ -290,7 +290,7 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
// PushUpdateAddDeleteTags updates a number of added and delete tags // PushUpdateAddDeleteTags updates a number of added and delete tags
func PushUpdateAddDeleteTags(repo *repo_model.Repository, gitRepo *git.Repository, addTags, delTags []string) error { 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 { if err := repo_model.PushUpdateDeleteTagsContext(ctx, repo, delTags); err != nil {
return err return err
} }

View file

@ -90,7 +90,7 @@ func Init() error {
// UpdateRepository updates a repository // UpdateRepository updates a repository
func UpdateRepository(repo *repo_model.Repository, visibilityChanged bool) (err error) { 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 { if err != nil {
return err return err
} }

View file

@ -48,7 +48,7 @@ func GenerateRepository(doer, owner *user_model.User, templateRepo *repo_model.R
} }
var generateRepo *repo_model.Repository 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) generateRepo, err = repo_module.GenerateRepository(ctx, doer, owner, templateRepo, opts)
if err != nil { if err != nil {
return err return err

View file

@ -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 { if err != nil {
return err return err
} }
@ -235,7 +235,7 @@ func UploadAvatar(u *user_model.User, data []byte) error {
return err return err
} }
ctx, committer, err := db.TxContext() ctx, committer, err := db.TxContext(db.DefaultContext)
if err != nil { if err != nil {
return err return err
} }