Skip to content

Commit 71c3dc8

Browse files
authored
chore: update indexes for workflow runs pagination (#1609)
Signed-off-by: Miguel Martinez <[email protected]>
1 parent 0545a4a commit 71c3dc8

File tree

6 files changed

+46
-4
lines changed

6 files changed

+46
-4
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Drop index "workflowrun_created_at_id" from table: "workflow_runs"
2+
DROP INDEX "workflowrun_created_at_id";
3+
-- Drop index "workflowrun_created_at_state" from table: "workflow_runs"
4+
DROP INDEX "workflowrun_created_at_state";
5+
-- Drop index "workflowrun_created_at_workflow_id" from table: "workflow_runs"
6+
DROP INDEX "workflowrun_created_at_workflow_id";
7+
-- Create index "workflowrun_created_at_id" to table: "workflow_runs"
8+
CREATE INDEX "workflowrun_created_at_id" ON "workflow_runs" ("created_at" DESC, "id");
9+
-- Create index "workflowrun_created_at_state" to table: "workflow_runs"
10+
CREATE INDEX "workflowrun_created_at_state" ON "workflow_runs" ("created_at" DESC, "state");
11+
-- Create index "workflowrun_created_at_workflow_id" to table: "workflow_runs"
12+
CREATE INDEX "workflowrun_created_at_workflow_id" ON "workflow_runs" ("created_at" DESC, "workflow_id");
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Create index "workflow_organization_id" to table: "workflows"
2+
CREATE INDEX "workflow_organization_id" ON "workflows" ("organization_id") WHERE (deleted_at IS NULL);

app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
h1:cd7peHu3MdqEo1c6vGrDGeDjSLGEFrPqrrEiSMDZJp0=
1+
h1:Igi2AdQrKbr6iehJdtxkal0vZYJOo0Z7OpmB0/T9rk0=
22
20230706165452_init-schema.sql h1:VvqbNFEQnCvUVyj2iDYVQQxDM0+sSXqocpt/5H64k8M=
33
20230710111950-cas-backend.sql h1:A8iBuSzZIEbdsv9ipBtscZQuaBp3V5/VMw7eZH6GX+g=
44
20230712094107-cas-backends-workflow-runs.sql h1:a5rzxpVGyd56nLRSsKrmCFc9sebg65RWzLghKHh5xvI=
@@ -69,3 +69,5 @@ h1:cd7peHu3MdqEo1c6vGrDGeDjSLGEFrPqrrEiSMDZJp0=
6969
20241123163942.sql h1:s+ImKf84B5s3Hp9Q7ILTcbNkQFIveZapu8fSe3X0eLY=
7070
20241126164629.sql h1:TrYF9F2RmBUVVB/9a3XFlintq94b2/BaJLYjv80TXOQ=
7171
20241126182209.sql h1:01eeRbQxKYsjhEvafp1fL4kYJx4NoidwjcxWbWLlNak=
72+
20241129164322.sql h1:QYuxTg1P//afuTEzzopH/D6mexMm3UVuIIwlaxCWGOA=
73+
20241129170353.sql h1:9RmXI0seY855RHiJx1+tfd3iwf9R5HR+3EsWmZdH6nw=

app/controlplane/pkg/data/ent/migrate/schema.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,14 @@ var (
471471
Where: "deleted_at IS NULL",
472472
},
473473
},
474+
{
475+
Name: "workflow_organization_id",
476+
Unique: false,
477+
Columns: []*schema.Column{WorkflowsColumns[10]},
478+
Annotation: &entsql.IndexAnnotation{
479+
Where: "deleted_at IS NULL",
480+
},
481+
},
474482
{
475483
Name: "workflow_workflow_contract",
476484
Unique: false,
@@ -593,11 +601,21 @@ var (
593601
Name: "workflowrun_created_at_id",
594602
Unique: false,
595603
Columns: []*schema.Column{WorkflowRunsColumns[1], WorkflowRunsColumns[0]},
604+
Annotation: &entsql.IndexAnnotation{
605+
DescColumns: map[string]bool{
606+
WorkflowRunsColumns[1].Name: true,
607+
},
608+
},
596609
},
597610
{
598611
Name: "workflowrun_created_at_state",
599612
Unique: false,
600613
Columns: []*schema.Column{WorkflowRunsColumns[1], WorkflowRunsColumns[3]},
614+
Annotation: &entsql.IndexAnnotation{
615+
DescColumns: map[string]bool{
616+
WorkflowRunsColumns[1].Name: true,
617+
},
618+
},
601619
},
602620
{
603621
Name: "workflowrun_attestation_digest",
@@ -613,6 +631,11 @@ var (
613631
Name: "workflowrun_created_at_workflow_id",
614632
Unique: false,
615633
Columns: []*schema.Column{WorkflowRunsColumns[1], WorkflowRunsColumns[13]},
634+
Annotation: &entsql.IndexAnnotation{
635+
DescColumns: map[string]bool{
636+
WorkflowRunsColumns[1].Name: true,
637+
},
638+
},
616639
},
617640
},
618641
}

app/controlplane/pkg/data/ent/schema/workflow.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ func (Workflow) Indexes() []ent.Index {
8686
index.Fields("organization_id", "id").Unique().Annotations(
8787
entsql.IndexWhere("deleted_at IS NULL"),
8888
),
89+
index.Fields("organization_id").Annotations(
90+
entsql.IndexWhere("deleted_at IS NULL"),
91+
),
8992
index.Edges("contract").Annotations(
9093
entsql.IndexWhere("deleted_at IS NULL"),
9194
),

app/controlplane/pkg/data/ent/schema/workflowrun.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ func (WorkflowRun) Edges() []ent.Edge {
7979
func (WorkflowRun) Indexes() []ent.Index {
8080
return []ent.Index{
8181
// Cursor pagination support
82-
index.Fields("created_at", "id"),
82+
index.Fields("created_at", "id").Annotations(entsql.DescColumns("created_at")),
8383
// Expiration job
84-
index.Fields("created_at", "state"),
84+
index.Fields("created_at", "state").Annotations(entsql.DescColumns("created_at")),
8585
index.Fields("attestation_digest"),
8686
index.Edges("workflow"),
8787
// DailyRun counts
88-
index.Edges("workflow").Fields("created_at"),
88+
index.Edges("workflow").Fields("created_at").Annotations(entsql.DescColumns("created_at")),
8989
}
9090
}

0 commit comments

Comments
 (0)