Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit af08f62

Browse files
committed
db: added index on scan_result
In particular, I've added the index on vulnerability_id and tag_id. As reported on #2053, this index makes the scanning of vulnerability issues way faster on large amounts of tags. Fixes #2053 Signed-off-by: Miquel Sabaté Solà <[email protected]>
1 parent 942f181 commit af08f62

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

app/models/scan_result.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
# created_at :datetime not null
1111
# updated_at :datetime not null
1212
#
13+
# Indexes
14+
#
15+
# index_scan_results_on_vulnerability_id_and_tag_id (vulnerability_id,tag_id)
16+
#
1317

1418
# Relationship linking tags and vulnerabilities: a scan result involves
1519
# vulnerabilities for tags.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddIndexScanResultsVulnerabilityTag < ActiveRecord::Migration
2+
def change
3+
add_index(:scan_results, [:vulnerability_id, :tag_id])
4+
end
5+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20180612145708) do
14+
ActiveRecord::Schema.define(version: 20181213101302) do
1515

1616
create_table "activities", force: :cascade do |t|
1717
t.integer "trackable_id", limit: 4
@@ -105,6 +105,8 @@
105105
t.datetime "updated_at", null: false
106106
end
107107

108+
add_index "scan_results", ["vulnerability_id", "tag_id"], name: "index_scan_results_on_vulnerability_id_and_tag_id", using: :btree
109+
108110
create_table "stars", force: :cascade do |t|
109111
t.integer "user_id", limit: 4
110112
t.integer "repository_id", limit: 4

0 commit comments

Comments
 (0)