Stop reading/writing last_image_scan, query image_scan directly#55
Open
Stop reading/writing last_image_scan, query image_scan directly#55
Conversation
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>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
divolgin
approved these changes
Mar 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
last_image_scantable inWriteScanResult()GetFixedCVEsFromLastScan) with aSELECT ... FROM image_scan ORDER BY created_at DESC LIMIT 1queryidx_image_scan_latest_lookupindex onimage_scan(image_name, image_tag, image_arch, created_at)to make the replacement query performantThe
last_image_scanschema definition is kept in place — dropping the table will be done in a follow-up PR.Why
The
last_image_scantable duplicated data already inimage_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, queryingimage_scandirectly is equivalent and eliminates the maintenance overhead of keeping a separate cache table in sync.Test plan
make build-workercompiles successfullyimage_catalog.last_scan_result_*andfixed_cve_count_*columns correctly after a scan cycleimage_scanby SchemaHero🤖 Generated with Claude Code