Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend Infra to Start Analyses #92

Merged
merged 4 commits into from
Jan 2, 2024
Merged

Backend Infra to Start Analyses #92

merged 4 commits into from
Jan 2, 2024

Conversation

gbdubs
Copy link
Contributor

@gbdubs gbdubs commented Dec 27, 2023

Creates the core endpoints for starting a run, looking up analysis runs and analysis artifacts. The centerpiece of this PR is the RunAnalysis endpoint.

Along the way, the PR makes a few misc cleanups:

  • Simplifies the interface of deleteBlobs
  • Fixes how we were doing enums in oapi so that the generated code generates shared definitions, simplifying and strengthening conversion.
  • Looks up the IDs of the artifacts associated with an analysis in the DB, using the query pattern of Front-end for Initiative Portfolio Participation #91 to avoid incorrect group-by patterns.

@gbdubs gbdubs requested a review from bcspragu December 27, 2023 20:27
cmd/server/pactasrv/analysis.go Show resolved Hide resolved
cmd/server/pactasrv/analysis.go Show resolved Hide resolved
cmd/server/pactasrv/analysis.go Show resolved Hide resolved
Comment on lines +13 to +42
return fmt.Sprintf(`
WITH selected_analysis_ids AS (
SELECT id FROM analysis %[1]s
)
SELECT
analysis.id,
analysis.analysis_type,
analysis.owner_id,
analysis.pacta_version_id,
analysis.portfolio_snapshot_id,
analysis.name,
analysis.description,
analysis.created_at,
analysis.ran_at,
analysis.completed_at,
analysis.failure_code,
analysis.failure_message,
aas.analysis_artifact_ids
FROM
analysis
LEFT JOIN (
SELECT
analysis_id,
ARRAY_AGG(analysis_artifact.id) AS analysis_artifact_ids
FROM analysis_artifact
WHERE analysis_id IN (SELECT id FROM selected_analysis_ids)
GROUP BY analysis_id
) aas ON aas.analysis_id = analysis.id
%[1]s;
`, where)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, this seems like lots of nested subqueries that we don't need. What's wrong with something like:

Suggested change
return fmt.Sprintf(`
WITH selected_analysis_ids AS (
SELECT id FROM analysis %[1]s
)
SELECT
analysis.id,
analysis.analysis_type,
analysis.owner_id,
analysis.pacta_version_id,
analysis.portfolio_snapshot_id,
analysis.name,
analysis.description,
analysis.created_at,
analysis.ran_at,
analysis.completed_at,
analysis.failure_code,
analysis.failure_message,
aas.analysis_artifact_ids
FROM
analysis
LEFT JOIN (
SELECT
analysis_id,
ARRAY_AGG(analysis_artifact.id) AS analysis_artifact_ids
FROM analysis_artifact
WHERE analysis_id IN (SELECT id FROM selected_analysis_ids)
GROUP BY analysis_id
) aas ON aas.analysis_id = analysis.id
%[1]s;
`, where)
return fmt.Sprintf(`
SELECT
analysis.id,
analysis.analysis_type,
analysis.owner_id,
analysis.pacta_version_id,
analysis.portfolio_snapshot_id,
analysis.name,
analysis.description,
analysis.created_at,
analysis.ran_at,
analysis.completed_at,
analysis.failure_code,
analysis.failure_message,
ARRAY_AGG(analysis_artifact.id)
FROM analysis
LEFT JOIN analysis_artifact
ON analysis_artifact.analysis_id = analysis.id
%[1]s ;; This is the WHERE clause I think. Also, I'd put the `WHERE ` here, so that all the callers don't have to remember it
GROUP by analysis.id;
`, where)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is mostly for consistency with the other query structure. The other query looked JUST like you're proposing. But then, when I added a second nested relationship table to the query, it broke. The advantage I see of structuring it this way is to prime it so that additional joins will follow the same structure, and be less likely to fall into the pitfall I spent a few hours having to debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copying this here for the discussion: #91 (comment)

openapi/pacta.yaml Show resolved Hide resolved
@gbdubs
Copy link
Contributor Author

gbdubs commented Dec 28, 2023

@bcspragu I'll wait on your response to the two questions above before merging - I want your opinion/perspective!

@gbdubs gbdubs requested a review from bcspragu December 28, 2023 15:25
@gbdubs gbdubs enabled auto-merge (squash) January 2, 2024 17:08
@gbdubs gbdubs merged commit c1257de into main Jan 2, 2024
2 checks passed
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