diff options
author | Jason Song <i@wolfogre.com> | 2023-01-09 11:50:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-09 11:50:54 +0800 |
commit | 7adc2de46404e32ed33f999d308ed56232cdfea5 (patch) | |
tree | 2404a22b5fa8a941eb5bfd16fd717fab29d899e4 /models/git/lfs_lock.go | |
parent | b878155b8741c2769b6aa50a80609c36822451c9 (diff) | |
download | gitea-7adc2de46404e32ed33f999d308ed56232cdfea5.tar.gz gitea-7adc2de46404e32ed33f999d308ed56232cdfea5.zip |
Use context parameter in models/git (#22367)
After #22362, we can feel free to use transactions without
`db.DefaultContext`.
And there are still lots of models using `db.DefaultContext`, I think we
should refactor them carefully and one by one.
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'models/git/lfs_lock.go')
-rw-r--r-- | models/git/lfs_lock.go | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/models/git/lfs_lock.go b/models/git/lfs_lock.go index dc5b0a2ced..25480f3f96 100644 --- a/models/git/lfs_lock.go +++ b/models/git/lfs_lock.go @@ -42,8 +42,8 @@ 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(db.DefaultContext) +func CreateLFSLock(ctx context.Context, repo *repo_model.Repository, lock *LFSLock) (*LFSLock, error) { + dbCtx, committer, err := db.TxContext(ctx) if err != nil { return nil, err } @@ -98,8 +98,8 @@ func GetLFSLockByID(ctx context.Context, id int64) (*LFSLock, error) { } // GetLFSLockByRepoID returns a list of locks of repository. -func GetLFSLockByRepoID(repoID int64, page, pageSize int) ([]*LFSLock, error) { - e := db.GetEngine(db.DefaultContext) +func GetLFSLockByRepoID(ctx context.Context, repoID int64, page, pageSize int) ([]*LFSLock, error) { + e := db.GetEngine(ctx) if page >= 0 && pageSize > 0 { start := 0 if page > 0 { @@ -112,12 +112,12 @@ func GetLFSLockByRepoID(repoID int64, page, pageSize int) ([]*LFSLock, error) { } // GetTreePathLock returns LSF lock for the treePath -func GetTreePathLock(repoID int64, treePath string) (*LFSLock, error) { +func GetTreePathLock(ctx context.Context, repoID int64, treePath string) (*LFSLock, error) { if !setting.LFS.StartServer { return nil, nil } - locks, err := GetLFSLockByRepoID(repoID, 0, 0) + locks, err := GetLFSLockByRepoID(ctx, repoID, 0, 0) if err != nil { return nil, err } @@ -130,13 +130,13 @@ func GetTreePathLock(repoID int64, treePath string) (*LFSLock, error) { } // CountLFSLockByRepoID returns a count of all LFSLocks associated with a repository. -func CountLFSLockByRepoID(repoID int64) (int64, error) { - return db.GetEngine(db.DefaultContext).Count(&LFSLock{RepoID: repoID}) +func CountLFSLockByRepoID(ctx context.Context, repoID int64) (int64, error) { + return db.GetEngine(ctx).Count(&LFSLock{RepoID: repoID}) } // 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(db.DefaultContext) +func DeleteLFSLockByID(ctx context.Context, id int64, repo *repo_model.Repository, u *user_model.User, force bool) (*LFSLock, error) { + dbCtx, committer, err := db.TxContext(ctx) if err != nil { return nil, err } |