Skip to content

Commit 3b4b3a5

Browse files
committed
Fix query_builder and ou_vuln updates
1 parent ff34d8d commit 3b4b3a5

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

datastore/query_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func buildGetQuery(record *claircore.IndexRecord, opts *datastore.GetOpts) (stri
114114
"repo_key",
115115
"repo_uri",
116116
"fixed_in_version",
117-
"updater",
117+
"vuln.updater",
118118
).From("vuln").
119119
Join(goqu.I("metadata").As("desc"), goqu.On(goqu.Ex{"vuln.description_id": goqu.I("desc.id")})).
120120
Join(goqu.I("metadata").As("name"), goqu.On(goqu.Ex{"vuln.name_id": goqu.I("name.id")})).

datastore/sqlite_store.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@ func (ms *sqliteMatcherStore) updateVulnerabilities(ctx context.Context, updater
488488
err = fmt.Errorf("failed to insert vulnerability: %w", err)
489489
return false
490490
}
491+
if _, err = tx.ExecContext(ctx, assoc, hashKind, hash, uoID); err != nil {
492+
err = fmt.Errorf("failed to assoc vulnerability: %w", err)
493+
return false
494+
}
491495

492496
return true
493497
})

migrations/03-updates.sql

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ CREATE TABLE IF NOT EXISTS uo_vuln (
2828
CREATE INDEX uo_vuln_vuln_idx ON uo_vuln (vuln);
2929
CREATE INDEX uo_vuln_uo_idx ON uo_vuln (uo);
3030

31-
-- Latest_vuln is a helper view to get the current snapshot of the vuln database.
32-
CREATE VIEW latest_vuln AS
33-
SELECT v.*
34-
FROM (SELECT id FROM update_operation GROUP BY updater ORDER BY updater, id DESC) uo
35-
JOIN uo_vuln ON uo_vuln.uo = uo.id
36-
JOIN vuln v ON uo_vuln.vuln = v.id;
37-
3831
CREATE TABLE uo_enrich
3932
(
4033
uo INTEGER NOT NULL,
@@ -62,6 +55,6 @@ CREATE TABLE updater_status (
6255
-- Create view that maintains the lastest update_operation id per updater.
6356
-- TODO: Materialized?
6457
CREATE VIEW latest_update_operations AS
65-
SELECT id, kind, updater FROM update_operation GROUP BY updater ORDER BY updater, id DESC;
58+
SELECT MAX(id) as id, kind, updater FROM update_operation GROUP BY updater;
6659

6760
CREATE INDEX enrichment_updater_idx ON enrichment (updater);

0 commit comments

Comments
 (0)