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

Commit

Permalink
Add index to optimize for list task executions for node execution (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
katrogan committed Sep 1, 2020
1 parent bf159e5 commit ff64ab8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
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

0 comments on commit ff64ab8

Please sign in to comment.