Defer loading of ansible_facts in HostLatestSummaryQuerySet - #628
Open
ssimpson89 wants to merge 1 commit into
Open
Defer loading of ansible_facts in HostLatestSummaryQuerySet#628ssimpson89 wants to merge 1 commit into
ssimpson89 wants to merge 1 commit into
Conversation
…ze performance Signed-off-by: Stephen Simpson <stevo81989@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses API performance issues when listing/retrieving Hosts by preventing the large ansible_facts JSON column from being loaded unnecessarily. It does this by deferring the ansible_facts field on the HostLatestSummaryQuerySet.with_latest_summary_id() path, which is used by Host list/detail API views.
Changes:
- Defer loading of
Host.ansible_factswhen usingwith_latest_summary_id()to reduce query payload size for host list/detail requests.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
47
to
+53
| def with_latest_summary_id(self): | ||
| from awx.main.models.jobs import JobHostSummary | ||
|
|
||
| latest_summary = JobHostSummary.objects.filter(host_id=OuterRef('pk')).order_by('-id') | ||
| return self.annotate( | ||
| _latest_summary_id=Subquery(latest_summary.values('id')[:1]), | ||
| ) | ||
| ).defer('ansible_facts') |
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
I was seeing performance issues loading a fairly small number of hosts in my environment, on the order of 5-8 seconds just for the page to load. I asked Claude to look into it, and it found that the full
ansible_factsJSON blob was being loaded from the database for every host on every list/detail request, even though it's never rendered in the response.The fix defers loading of the
ansible_factscolumn inHostLatestSummaryQuerySet.with_latest_summary_id().I tested this in my own environment and didn't see any regressions.
ISSUE TYPE
COMPONENT NAME
ASCENDER VERSION