-
Notifications
You must be signed in to change notification settings - Fork 56
Filter out Copr builds without SRPM in SQL #2863
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -41,6 +41,7 @@ | |||||||||||||||||||||||||
| desc, | ||||||||||||||||||||||||||
| func, | ||||||||||||||||||||||||||
| null, | ||||||||||||||||||||||||||
| or_, | ||||||||||||||||||||||||||
| select, | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| from sqlalchemy.dialects.postgresql import array as psql_array | ||||||||||||||||||||||||||
|
|
@@ -2240,6 +2241,19 @@ def get_merged_chroots( | |||||||||||||||||||||||||
| "packit_id_per_chroot", | ||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| .filter( | ||||||||||||||||||||||||||
| # Exclude builds without build_id (to not mix targets from | ||||||||||||||||||||||||||
| # different builds together) | ||||||||||||||||||||||||||
| CoprBuildTargetModel.build_id.isnot(None), | ||||||||||||||||||||||||||
| # Exclude builds waiting for SRPM - not actual Copr builds yet | ||||||||||||||||||||||||||
| CoprBuildTargetModel.status != BuildStatus.waiting_for_srpm, | ||||||||||||||||||||||||||
| # Exclude SRPM build failures (no build_start_time/build_logs_url) | ||||||||||||||||||||||||||
| or_( | ||||||||||||||||||||||||||
| CoprBuildTargetModel.status != BuildStatus.failure, | ||||||||||||||||||||||||||
| CoprBuildTargetModel.build_start_time.isnot(None), | ||||||||||||||||||||||||||
| CoprBuildTargetModel.build_logs_url.isnot(None), | ||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||
|
Comment on lines
+2251
to
+2255
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this
Suggested change
|
||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
| .group_by( | ||||||||||||||||||||||||||
| CoprBuildTargetModel.build_id, | ||||||||||||||||||||||||||
| ) # Group by identical element(s) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,6 @@ | |
| from flask_restx import Namespace, Resource | ||
|
|
||
| from packit_service.models import ( | ||
| BuildStatus, | ||
| CoprBuildGroupModel, | ||
| CoprBuildTargetModel, | ||
| optional_timestamp, | ||
|
|
@@ -35,15 +34,6 @@ def get(self): | |
| first, last = indices() | ||
| for build in CoprBuildTargetModel.get_merged_chroots(first, last): | ||
| build_info = CoprBuildTargetModel.get_by_build_id(build.build_id, None) | ||
| if build_info.status == BuildStatus.waiting_for_srpm: | ||
| continue | ||
| if ( | ||
| build_info.status == BuildStatus.failure | ||
| and not build_info.build_start_time | ||
| and not build_info.build_logs_url | ||
| ): | ||
| # SRPM build failed, it doesn't make sense to list this build | ||
| continue | ||
| project_info = build_info.get_project() | ||
|
Comment on lines
35
to
37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This loop currently causes an N+1 query problem. For each build returned by To resolve this, I recommend modifying For example, you could extend the query in This would make the API endpoint much more performant.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense, but is out of scope here. If we wanted to optimize the code, it should be tracked as a separate issue. |
||
| build_dict = { | ||
| "packit_id": build_info.id, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To improve the readability of the filter condition being added, consider importing
and_andnot_instead ofor_. This will allow expressing the filter logic in a way that more directly mirrors the case being excluded, making the code easier to understand.