1
Fork 0

Small refactor to reduce unnecessary database queries and remove duplicated functions (#33779)

(cherry picked from commit 6c8fb8d455cfe25d5aa966674624bce99fba1735)
This commit is contained in:
Lunny Xiao 2025-03-04 10:25:20 -08:00 committed by Gusted
parent 49694242d4
commit 0a52be2a04
No known key found for this signature in database
GPG key ID: FD821B732837125F
6 changed files with 22 additions and 7 deletions

View file

@ -45,15 +45,12 @@ func init() {
// GetSchedulesMapByIDs returns the schedules by given id slice.
func GetSchedulesMapByIDs(ctx context.Context, ids []int64) (map[int64]*ActionSchedule, error) {
schedules := make(map[int64]*ActionSchedule, len(ids))
if len(ids) == 0 {
return schedules, nil
}
return schedules, db.GetEngine(ctx).In("id", ids).Find(&schedules)
}
// GetReposMapByIDs returns the repos by given id slice.
func GetReposMapByIDs(ctx context.Context, ids []int64) (map[int64]*repo_model.Repository, error) {
repos := make(map[int64]*repo_model.Repository, len(ids))
return repos, db.GetEngine(ctx).In("id", ids).Find(&repos)
}
// CreateScheduleTask creates new schedule task.
func CreateScheduleTask(ctx context.Context, rows []*ActionSchedule) error {
// Return early if there are no rows to insert