Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Add index to optimize for list task executions for node execution #120

Merged
merged 1 commit into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/repositories/config/migration_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ type NodeExecution struct {

type TaskExecutionKey struct {
TaskKey
NodeExecutionKey
Project string `gorm:"primary_key;column:execution_project;index:idx_task_executions_exec"`
Domain string `gorm:"primary_key;column:execution_domain;index:idx_task_executions_exec"`
Name string `gorm:"primary_key;column:execution_name;index:idx_task_executions_exec"`
NodeID string `gorm:"primary_key;index:idx_task_executions_exec;index"`
// *IMPORTANT* This is a pointer to an int in order to allow setting an empty ("0") value according to gorm convention.
// Because RetryAttempt is part of the TaskExecution primary key is should *never* be null.
RetryAttempt *uint32 `gorm:"primary_key;AUTO_INCREMENT:FALSE"`
Expand Down
9 changes: 9 additions & 0 deletions pkg/repositories/config/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,13 @@ var Migrations = []*gormigrate.Migration{
return tx.Model(&models.Project{}).DropColumn("labels").Error
},
},
{
ID: "2020-09-01-task-exec-idx",
Migrate: func(tx *gorm.DB) error {
return tx.AutoMigrate(&TaskExecution{}).Error
},
Rollback: func(tx *gorm.DB) error {
return tx.Model(&TaskExecution{}).RemoveIndex("idx_task_executions_exec").Error
},
},
}
6 changes: 3 additions & 3 deletions tests/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestUpdateProjectDescription(t *testing.T) {

// Verify that the project's Name has not been modified but the Description has.
updatedProject := projectsUpdated.Projects[0]
assert.Equal(t, updatedProject.Id, "potato") // unchanged
assert.Equal(t, updatedProject.Id, "potato") // unchanged
assert.Equal(t, updatedProject.Name, "foobar") // changed
assert.Equal(t, updatedProject.Description, "a-new-description") // changed

Expand Down Expand Up @@ -148,8 +148,8 @@ func TestUpdateProjectLabels(t *testing.T) {
// Check the name has been modified.
// Verify that the project's Name has not been modified but the Description has.
updatedProject := projectsUpdated.Projects[0]
assert.Equal(t, updatedProject.Id, "potato") // unchanged
assert.Equal(t, updatedProject.Name, "foobar") // changed
assert.Equal(t, updatedProject.Id, "potato") // unchanged
assert.Equal(t, updatedProject.Name, "foobar") // changed

// Verify that the expected labels have been added to the project.
labelsMap := updatedProject.Labels
Expand Down