Skip to content

Commit

Permalink
Speed up common CertifyVuln ent queries by adding indexes (#1999)
Browse files Browse the repository at this point in the history
* Speed up common CertifyVuln ent queries by adding indexes

Signed-off-by: Narsimham Chelluri (Narsa) <narsa@kusari.dev>

* Add PR checklist item for ent schema changes

Signed-off-by: Narsimham Chelluri (Narsa) <narsa@kusari.dev>

---------

Signed-off-by: Narsimham Chelluri (Narsa) <narsa@kusari.dev>
  • Loading branch information
nchelluri authored Jul 3, 2024
1 parent 6a63c22 commit 0675b67
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [ ] If GraphQL schema is changed, `make generate` has been run
- [ ] If GraphQL schema is changed, GraphQL client updates/additions have been made
- [ ] If OpenAPI spec is changed, `make generate` has been run
- [ ] If ent schema is changed, `make generate` has been run
- [ ] If `collectsub` protobuf has been changed, `make proto` has been run
- [ ] All CI checks are passing (tests and formatting)
- [ ] All dependent PRs have already been merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Create index "certifyvuln_package_id" to table: "certify_vulns"
CREATE INDEX "certifyvuln_package_id" ON "certify_vulns" ("package_id");
-- Create index "vulnerabilityid_type" to table: "vulnerability_ids"
CREATE INDEX "vulnerabilityid_type" ON "vulnerability_ids" ("type");
3 changes: 2 additions & 1 deletion pkg/assembler/backends/ent/migrate/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
h1:Z0P5t/epO2WlS9l+KgcJj/fXXUbYqg9ASBTrDwiUVQ4=
h1:MoIYlS2hykbmbtvX1IGRCx04rxWGYVC8aJqjVBnEDak=
20240503123155_baseline.sql h1:oZtbKI8sJj3xQq7ibfvfhFoVl+Oa67CWP7DFrsVLVds=
20240626153721_ent_diff.sql h1:FvV1xELikdPbtJk7kxIZn9MhvVVoFLF/2/iT/wM5RkA=
20240702195630_ent_diff.sql h1:y8TgeUg35krYVORmC7cN4O96HqOc3mVO9IQ2lYzIzwg=
10 changes: 10 additions & 0 deletions pkg/assembler/backends/ent/migrate/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/assembler/backends/ent/schema/certifyvuln.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ func (CertifyVuln) Edges() []ent.Edge {
func (CertifyVuln) Indexes() []ent.Index {
return []ent.Index{
index.Fields("db_uri", "db_version", "scanner_uri", "scanner_version", "origin", "collector", "time_scanned", "document_ref").Edges("vulnerability", "package").Unique(),
index.Fields("package_id"), // speed up frequently run queries to check when CV nodes affect certain package IDs
}
}
1 change: 1 addition & 0 deletions pkg/assembler/backends/ent/schema/vulnerabilityid.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ func (VulnerabilityID) Edges() []ent.Edge {
func (VulnerabilityID) Indexes() []ent.Index {
return []ent.Index{
index.Fields("vulnerability_id", "type").Unique(),
index.Fields("type"), // speed up frequently run queries to check when vuln type is not novuln
}
}

0 comments on commit 0675b67

Please sign in to comment.