Skip to content

Defer loading of ansible_facts in HostLatestSummaryQuerySet - #628

Open
ssimpson89 wants to merge 1 commit into
ctrliq:mainfrom
ssimpson89:fix/host-defer-ansible-facts
Open

Defer loading of ansible_facts in HostLatestSummaryQuerySet#628
ssimpson89 wants to merge 1 commit into
ctrliq:mainfrom
ssimpson89:fix/host-defer-ansible-facts

Conversation

@ssimpson89

Copy link
Copy Markdown
Contributor
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_facts JSON 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_facts column in HostLatestSummaryQuerySet.with_latest_summary_id().

I tested this in my own environment and didn't see any regressions.

ISSUE TYPE
  • Bug Fix
COMPONENT NAME
  • API
ASCENDER VERSION
25.5.1

…ze performance

Signed-off-by: Stephen Simpson <stevo81989@gmail.com>
Copilot AI lite review requested due to automatic review settings August 9, 2026 02:51

Copilot AI left a comment

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.

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_facts when using with_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 thread awx/main/managers.py
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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants