aboutsummaryrefslogtreecommitdiffstats
path: root/models/issues/milestone_list.go
diff options
context:
space:
mode:
authorJakobDev <jakobdev@gmx.de>2023-09-16 16:39:12 +0200
committerGitHub <noreply@github.com>2023-09-16 14:39:12 +0000
commitf91dbbba98c841f11d99be998ed5dd98122a457c (patch)
tree9c6c935ccf745c5a1716f1330922354809cd39e0 /models/issues/milestone_list.go
parenta1b2a118123e0abd1d4737f4a6c0cf56d15eff57 (diff)
downloadgitea-f91dbbba98c841f11d99be998ed5dd98122a457c.tar.gz
gitea-f91dbbba98c841f11d99be998ed5dd98122a457c.zip
Next round of `db.DefaultContext` refactor (#27089)
Part of #27065
Diffstat (limited to 'models/issues/milestone_list.go')
-rw-r--r--models/issues/milestone_list.go35
1 files changed, 16 insertions, 19 deletions
diff --git a/models/issues/milestone_list.go b/models/issues/milestone_list.go
index b0c29106a0..d5c9b1358c 100644
--- a/models/issues/milestone_list.go
+++ b/models/issues/milestone_list.go
@@ -100,9 +100,9 @@ func GetMilestoneIDsByNames(ctx context.Context, names []string) ([]int64, error
}
// SearchMilestones search milestones
-func SearchMilestones(repoCond builder.Cond, page int, isClosed bool, sortType, keyword string) (MilestoneList, error) {
+func SearchMilestones(ctx context.Context, repoCond builder.Cond, page int, isClosed bool, sortType, keyword string) (MilestoneList, error) {
miles := make([]*Milestone, 0, setting.UI.IssuePagingNum)
- sess := db.GetEngine(db.DefaultContext).Where("is_closed = ?", isClosed)
+ sess := db.GetEngine(ctx).Where("is_closed = ?", isClosed)
if len(keyword) > 0 {
sess = sess.And(builder.Like{"UPPER(name)", strings.ToUpper(keyword)})
}
@@ -131,8 +131,9 @@ func SearchMilestones(repoCond builder.Cond, page int, isClosed bool, sortType,
}
// GetMilestonesByRepoIDs returns a list of milestones of given repositories and status.
-func GetMilestonesByRepoIDs(repoIDs []int64, page int, isClosed bool, sortType string) (MilestoneList, error) {
+func GetMilestonesByRepoIDs(ctx context.Context, repoIDs []int64, page int, isClosed bool, sortType string) (MilestoneList, error) {
return SearchMilestones(
+ ctx,
builder.In("repo_id", repoIDs),
page,
isClosed,
@@ -141,7 +142,8 @@ func GetMilestonesByRepoIDs(repoIDs []int64, page int, isClosed bool, sortType s
)
}
-func (milestones MilestoneList) loadTotalTrackedTimes(ctx context.Context) error {
+// LoadTotalTrackedTimes loads for every milestone in the list the TotalTrackedTime by a batch request
+func (milestones MilestoneList) LoadTotalTrackedTimes(ctx context.Context) error {
type totalTimesByMilestone struct {
MilestoneID int64
Time int64
@@ -181,11 +183,6 @@ func (milestones MilestoneList) loadTotalTrackedTimes(ctx context.Context) error
return nil
}
-// LoadTotalTrackedTimes loads for every milestone in the list the TotalTrackedTime by a batch request
-func (milestones MilestoneList) LoadTotalTrackedTimes() error {
- return milestones.loadTotalTrackedTimes(db.DefaultContext)
-}
-
// CountMilestones returns number of milestones in given repository with other options
func CountMilestones(ctx context.Context, opts GetMilestonesOption) (int64, error) {
return db.GetEngine(ctx).
@@ -194,8 +191,8 @@ func CountMilestones(ctx context.Context, opts GetMilestonesOption) (int64, erro
}
// CountMilestonesByRepoCond map from repo conditions to number of milestones matching the options`
-func CountMilestonesByRepoCond(repoCond builder.Cond, isClosed bool) (map[int64]int64, error) {
- sess := db.GetEngine(db.DefaultContext).Where("is_closed = ?", isClosed)
+func CountMilestonesByRepoCond(ctx context.Context, repoCond builder.Cond, isClosed bool) (map[int64]int64, error) {
+ sess := db.GetEngine(ctx).Where("is_closed = ?", isClosed)
if repoCond.IsValid() {
sess.In("repo_id", builder.Select("id").From("repository").Where(repoCond))
}
@@ -219,8 +216,8 @@ func CountMilestonesByRepoCond(repoCond builder.Cond, isClosed bool) (map[int64]
}
// CountMilestonesByRepoCondAndKw map from repo conditions and the keyword of milestones' name to number of milestones matching the options`
-func CountMilestonesByRepoCondAndKw(repoCond builder.Cond, keyword string, isClosed bool) (map[int64]int64, error) {
- sess := db.GetEngine(db.DefaultContext).Where("is_closed = ?", isClosed)
+func CountMilestonesByRepoCondAndKw(ctx context.Context, repoCond builder.Cond, keyword string, isClosed bool) (map[int64]int64, error) {
+ sess := db.GetEngine(ctx).Where("is_closed = ?", isClosed)
if len(keyword) > 0 {
sess = sess.And(builder.Like{"UPPER(name)", strings.ToUpper(keyword)})
}
@@ -257,11 +254,11 @@ func (m MilestonesStats) Total() int64 {
}
// GetMilestonesStatsByRepoCond returns milestone statistic information for dashboard by given conditions.
-func GetMilestonesStatsByRepoCond(repoCond builder.Cond) (*MilestonesStats, error) {
+func GetMilestonesStatsByRepoCond(ctx context.Context, repoCond builder.Cond) (*MilestonesStats, error) {
var err error
stats := &MilestonesStats{}
- sess := db.GetEngine(db.DefaultContext).Where("is_closed = ?", false)
+ sess := db.GetEngine(ctx).Where("is_closed = ?", false)
if repoCond.IsValid() {
sess.And(builder.In("repo_id", builder.Select("id").From("repository").Where(repoCond)))
}
@@ -270,7 +267,7 @@ func GetMilestonesStatsByRepoCond(repoCond builder.Cond) (*MilestonesStats, erro
return nil, err
}
- sess = db.GetEngine(db.DefaultContext).Where("is_closed = ?", true)
+ sess = db.GetEngine(ctx).Where("is_closed = ?", true)
if repoCond.IsValid() {
sess.And(builder.In("repo_id", builder.Select("id").From("repository").Where(repoCond)))
}
@@ -283,11 +280,11 @@ func GetMilestonesStatsByRepoCond(repoCond builder.Cond) (*MilestonesStats, erro
}
// GetMilestonesStatsByRepoCondAndKw returns milestone statistic information for dashboard by given repo conditions and name keyword.
-func GetMilestonesStatsByRepoCondAndKw(repoCond builder.Cond, keyword string) (*MilestonesStats, error) {
+func GetMilestonesStatsByRepoCondAndKw(ctx context.Context, repoCond builder.Cond, keyword string) (*MilestonesStats, error) {
var err error
stats := &MilestonesStats{}
- sess := db.GetEngine(db.DefaultContext).Where("is_closed = ?", false)
+ sess := db.GetEngine(ctx).Where("is_closed = ?", false)
if len(keyword) > 0 {
sess = sess.And(builder.Like{"UPPER(name)", strings.ToUpper(keyword)})
}
@@ -299,7 +296,7 @@ func GetMilestonesStatsByRepoCondAndKw(repoCond builder.Cond, keyword string) (*
return nil, err
}
- sess = db.GetEngine(db.DefaultContext).Where("is_closed = ?", true)
+ sess = db.GetEngine(ctx).Where("is_closed = ?", true)
if len(keyword) > 0 {
sess = sess.And(builder.Like{"UPPER(name)", strings.ToUpper(keyword)})
}