mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-19 11:00:02 +02:00
Add context.Context
to more methods (#21546)
This PR adds a context parameter to a bunch of methods. Some helper `xxxCtx()` methods got replaced with the normal name now. Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
fefdb7ffd1
commit
044c754ea5
148 changed files with 1411 additions and 1564 deletions
|
@ -90,7 +90,8 @@ func init() {
|
|||
db.RegisterModel(new(Release))
|
||||
}
|
||||
|
||||
func (r *Release) loadAttributes(ctx context.Context) error {
|
||||
// LoadAttributes load repo and publisher attributes for a release
|
||||
func (r *Release) LoadAttributes(ctx context.Context) error {
|
||||
var err error
|
||||
if r.Repo == nil {
|
||||
r.Repo, err = GetRepositoryByIDCtx(ctx, r.RepoID)
|
||||
|
@ -111,11 +112,6 @@ func (r *Release) loadAttributes(ctx context.Context) error {
|
|||
return GetReleaseAttachments(ctx, r)
|
||||
}
|
||||
|
||||
// LoadAttributes load repo and publisher attributes for a release
|
||||
func (r *Release) LoadAttributes() error {
|
||||
return r.loadAttributes(db.DefaultContext)
|
||||
}
|
||||
|
||||
// APIURL the api url for a release. release must have attributes loaded
|
||||
func (r *Release) APIURL() string {
|
||||
return r.Repo.APIURL() + "/releases/" + strconv.FormatInt(r.ID, 10)
|
||||
|
@ -241,8 +237,8 @@ func (opts *FindReleasesOptions) toConds(repoID int64) builder.Cond {
|
|||
}
|
||||
|
||||
// GetReleasesByRepoID returns a list of releases of repository.
|
||||
func GetReleasesByRepoID(repoID int64, opts FindReleasesOptions) ([]*Release, error) {
|
||||
sess := db.GetEngine(db.DefaultContext).
|
||||
func GetReleasesByRepoID(ctx context.Context, repoID int64, opts FindReleasesOptions) ([]*Release, error) {
|
||||
sess := db.GetEngine(ctx).
|
||||
Desc("created_unix", "id").
|
||||
Where(opts.toConds(repoID))
|
||||
|
||||
|
@ -381,8 +377,8 @@ func SortReleases(rels []*Release) {
|
|||
}
|
||||
|
||||
// DeleteReleaseByID deletes a release from database by given ID.
|
||||
func DeleteReleaseByID(id int64) error {
|
||||
_, err := db.GetEngine(db.DefaultContext).ID(id).Delete(new(Release))
|
||||
func DeleteReleaseByID(ctx context.Context, id int64) error {
|
||||
_, err := db.GetEngine(ctx).ID(id).Delete(new(Release))
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue