Skip to content

refactor: Improvements to database querying, notify missing records#5527

Open
michaelkedar wants to merge 6 commits into
google:masterfrom
michaelkedar:💬⛔🐍

Hidden character warning

The head ref may contain hidden characters: "\ud83d\udcac\u26d4\ud83d\udc0d"
Open

refactor: Improvements to database querying, notify missing records#5527
michaelkedar wants to merge 6 commits into
google:masterfrom
michaelkedar:💬⛔🐍

Conversation

@michaelkedar

Copy link
Copy Markdown
Member
  • Publish a gcs_missing message to the recoverer if a vuln matched in datastore, but no full records was found in GCS.
  • Create batch query methods on the vulnerability store interface, to allow more efficient queries to be done in a future postgres migration
  • Batch GetModified queries together across goroutines into a single datastore GetMulti request to save on network round trips.

@michaelkedar michaelkedar marked this pull request as ready for review June 11, 2026 05:25
@michaelkedar michaelkedar requested a review from another-rex June 11, 2026 05:25
Comment thread go/internal/osvutil/batcher/context.go Outdated
activeCount.Store(int64(len(subCtxs)))

for _, ctx := range subCtxs {
go func(c context.Context) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently there's this function called context.AfterFunc() which can be used here instead of us manually spawning a goroutine?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should result in a lot less goroutines because it'll all be managed by the parent context.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat - added

Comment on lines +43 to +44
BatchTimeout time.Duration
BatchMaxElements int

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to make these configurable in main.go? (Probably as env vars?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added some env var parsing

Comment on lines +202 to +203
// We check if the goroutine for req1 finished quickly
c1Done := make(chan struct{})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment say we check, but does this check? It only seems to be checking if c1Done is finished (both requests finished)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test should be fixed now

func (s *VulnerabilityStore) batchGetModified(ctx context.Context, ids []string) []batcher.Result[time.Time] {
results := make([]batcher.Result[time.Time], len(ids))

keys := make([]*datastore.Key, len(ids))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth deduping here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually probably not worth the additional logic, though maybe add a comment to state that's something considered.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment added

@michaelkedar michaelkedar requested a review from another-rex June 12, 2026 06:49
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