Skip to content

Stop reading/writing last_image_scan, query image_scan directly#55

Open
jdewinne wants to merge 2 commits intomainfrom
jdewinne/rm-last-image-scan
Open

Stop reading/writing last_image_scan, query image_scan directly#55
jdewinne wants to merge 2 commits intomainfrom
jdewinne/rm-last-image-scan

Conversation

@jdewinne
Copy link
Copy Markdown
Member

@jdewinne jdewinne commented Mar 20, 2026

Summary

  • Stops writing to the last_image_scan table in WriteScanResult()
  • Replaces the single read site (GetFixedCVEsFromLastScan) with a SELECT ... FROM image_scan ORDER BY created_at DESC LIMIT 1 query
  • Adds idx_image_scan_latest_lookup index on image_scan(image_name, image_tag, image_arch, created_at) to make the replacement query performant

The last_image_scan schema definition is kept in place — dropping the table will be done in a follow-up PR.

Why

The last_image_scan table duplicated data already in image_scan. It was only read by one function (GetFixedCVEsFromLastScan) in the Go backend to look up the alternate image's latest scan result for computing fixed CVE counts. With a proper index, querying image_scan directly is equivalent and eliminates the maintenance overhead of keeping a separate cache table in sync.

Test plan

  • Verify make build-worker compiles successfully
  • Verify scan results continue to populate image_catalog.last_scan_result_* and fixed_cve_count_* columns correctly after a scan cycle
  • Verify the security dashboard in securebuild-www still shows correct fixed CVE counts
  • Confirm the new index is created on image_scan by SchemaHero

🤖 Generated with Claude Code

The last_image_scan table was a materialized cache of the latest scan
result per (image_name, image_tag, image_arch). It was written on every
scan but only read by GetFixedCVEsFromLastScan() to look up the
alternate image's latest scan. This is replaceable with a simple
ORDER BY created_at DESC LIMIT 1 query on image_scan.

Changes:
- Add idx_image_scan_latest_lookup index on image_scan for efficient
  latest-record lookups by (image_name, image_tag, image_arch, created_at)
- Remove the upsert into last_image_scan from WriteScanResult()
- Rename GetFixedCVEsFromLastScan -> GetFixedCVEsFromLatestScan and
  query image_scan instead
- Delete the last-image-scan.yaml schema definition

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jdewinne jdewinne requested a review from a team as a code owner March 20, 2026 22:15
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jdewinne jdewinne changed the title Remove last_image_scan table, query image_scan directly Stop reading/writing last_image_scan, query image_scan directly Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants