feat: optimize build list query and add database indexes for search#1203
Open
andrewlukoshko wants to merge 1 commit intomasterfrom
Open
feat: optimize build list query and add database indexes for search#1203andrewlukoshko wants to merge 1 commit intomasterfrom
andrewlukoshko wants to merge 1 commit intomasterfrom
Conversation
The build list endpoint (GET /builds/) has several performance issues that make the frontend slow, especially when filtering by project name, ref, or RPM parameters. Query optimizations in get_builds(): - Make the BuildTaskArtifact LEFT OUTER JOIN conditional: only applied when RPM filter params (name, epoch, version, release, arch) are provided. Previously every request paid the cost of this JOIN plus a DISTINCT to deduplicate the multiplied rows. - Move the Pulp API call (get_rpm_packages) outside of generate_query() so it executes once instead of twice when paginating (data query + count query both called generate_query independently). - Reduce eager loading for paginated list queries: skip linked_builds, test_tasks.performance_stats, build_task.performance_stats, and sign_tasks which are not needed for the list view. Single build detail view still loads all relationships. Database indexes (Alembic migration): - GIN trigram indexes (pg_trgm) on build_task_refs.url and git_ref to accelerate LIKE '%pattern%' queries used for project and ref search. Regular B-tree indexes cannot help with infix LIKE patterns. - B-tree indexes on builds (owner_id, released, signed, finished_at), build_tasks.platform_id, and build_artifacts.href for commonly used WHERE filters. - GIN trigram indexes on new_errata_records title and original_title for errata title search. - B-tree indexes on new_errata_records (platform_id, release_status, issued_date) and a GIN trigram + B-tree index on new_errata_references.cve_id for CVE search. Note: the migration requires the pg_trgm PostgreSQL extension which is created automatically if not already present.
1774c2d to
f711f0c
Compare
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
BuildTaskArtifactLEFT OUTER JOIN conditional inget_builds()— only applied when RPM filter params are provided, avoiding unnecessary JOIN + DISTINCT on every requestget_rpm_packages()call outsidegenerate_query()so it executes once instead of twice when paginating (data + count queries)minimal=True) — skiplinked_builds,performance_stats, andsign_tasksnot needed for list viewpg_trgm) onbuild_task_refs.url/git_refand errata title fields for LIKE search, plus B-tree indexes on commonly filtered columns (owner_id,released,signed,finished_at,platform_id,href, errataplatform_id/release_status/issued_date/cve_id)Test plan
EXPLAIN ANALYZE)alembic upgrade headapplies migration cleanlypg_trgmextension is created on fresh database