Skip to content

Commit

Permalink
fix(tasks): fill tasks for sql
Browse files Browse the repository at this point in the history
  • Loading branch information
fiftin committed Jul 20, 2024
1 parent 7ea8d89 commit 21ba6c6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
6 changes: 5 additions & 1 deletion db/bolt/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ func (d *BoltDb) GetTemplates(projectID int, filter db.TemplateFilter, params db
}

tpl.LastTask = &db.TaskWithTpl{
Task: task,
Task: task,
TemplatePlaybook: tpl.Playbook,
TemplateAlias: tpl.Name,
TemplateType: tpl.Type,
TemplateApp: tpl.App,
}

unfilledTemplateCount--
Expand Down
10 changes: 7 additions & 3 deletions db/sql/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (d *SqlDb) CreateTaskOutput(output db.TaskOutput) (db.TaskOutput, error) {
return output, err
}

func (d *SqlDb) getTasks(projectID int, templateID *int, params db.RetrieveQueryParams, tasks *[]db.TaskWithTpl) (err error) {
func (d *SqlDb) getTasks(projectID int, templateID *int, taskIDs []int, params db.RetrieveQueryParams, tasks *[]db.TaskWithTpl) (err error) {
fields := "task.*"
fields += ", tpl.playbook as tpl_playbook" +
", `user`.name as user_name" +
Expand All @@ -131,6 +131,10 @@ func (d *SqlDb) getTasks(projectID int, templateID *int, params db.RetrieveQuery
q = q.Where("tpl.project_id=? AND task.template_id=?", projectID, templateID)
}

if len(taskIDs) > 0 {
q = q.Where(squirrel.Eq{"task.id": taskIDs})
}

if params.Count > 0 {
q = q.Limit(uint64(params.Count))
}
Expand Down Expand Up @@ -176,13 +180,13 @@ func (d *SqlDb) GetTask(projectID int, taskID int) (task db.Task, err error) {
}

func (d *SqlDb) GetTemplateTasks(projectID int, templateID int, params db.RetrieveQueryParams) (tasks []db.TaskWithTpl, err error) {
err = d.getTasks(projectID, &templateID, params, &tasks)
err = d.getTasks(projectID, &templateID, nil, params, &tasks)
return
}

func (d *SqlDb) GetProjectTasks(projectID int, params db.RetrieveQueryParams) (tasks []db.TaskWithTpl, err error) {
tasks = make([]db.TaskWithTpl, 0)
err = d.getTasks(projectID, nil, params, &tasks)
err = d.getTasks(projectID, nil, nil, params, &tasks)
return
}

Expand Down
17 changes: 6 additions & 11 deletions db/sql/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,6 @@ func (d *SqlDb) UpdateTemplate(template db.Template) error {
return err
}

func (d *SqlDb) getProjectTasksByIDs(projectID int, taskIDs []int) (tasks []db.Task, err error) {
err = d.getObjects(projectID, db.TaskProps, db.RetrieveQueryParams{}, func(builder squirrel.SelectBuilder) squirrel.SelectBuilder {
return builder.Where(squirrel.Eq{"id": taskIDs})
}, &tasks)

return
}

func (d *SqlDb) GetTemplates(projectID int, filter db.TemplateFilter, params db.RetrieveQueryParams) (templates []db.Template, err error) {

templates = []db.Template{}
Expand Down Expand Up @@ -201,7 +193,8 @@ func (d *SqlDb) GetTemplates(projectID int, filter db.TemplateFilter, params db.
}
}

tasks, err := d.getProjectTasksByIDs(projectID, taskIDs)
var tasks []db.TaskWithTpl
err = d.getTasks(projectID, nil, taskIDs, db.RetrieveQueryParams{}, &tasks)

if err != nil {
return
Expand All @@ -218,9 +211,11 @@ func (d *SqlDb) GetTemplates(projectID int, filter db.TemplateFilter, params db.
continue
}

template.LastTask = &db.TaskWithTpl{
Task: tsk,
err = tsk.Fill(d)
if err != nil {
return
}
template.LastTask = &tsk
break
}
templates = append(templates, template)
Expand Down

1 comment on commit 21ba6c6

@masterwishx
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems the fix broke new template visability , opened issue for it

Please sign in to comment.