Skip to content

Fixes #39298 - Use bulk insert for new fact values on persisted hosts#10979

Open
pablomh wants to merge 1 commit intotheforeman:developfrom
pablomh:registration/bulk-insert-fact-values
Open

Fixes #39298 - Use bulk insert for new fact values on persisted hosts#10979
pablomh wants to merge 1 commit intotheforeman:developfrom
pablomh:registration/bulk-insert-fact-values

Conversation

@pablomh
Copy link
Copy Markdown
Contributor

@pablomh pablomh commented May 7, 2026

Summary

Replace per-fact create! loop with a single insert_all for new facts on persisted hosts, reducing DB round-trips by ~94% (108 INSERTs → 6).

Changes

  • fact_importer.rb: add_new_facts partitions into compose facts (nil values, handled individually) and regular facts (bulk inserted via insert_all)
  • bulk_insert_new_fact_values: new method using FactValue.insert_all with unique_by: [:fact_name_id, :host_id]
  • Counter initialization: @counters = { added: 0, updated: 0, deleted: 0 } prevents nil access

How to test

  1. bundle exec rake test TEST=test/unit/fact_importer_test.rb
  2. Register a host and verify facts are imported correctly

Replace per-fact create! loop with a single insert_all for new facts
on persisted hosts. Compose/parent facts (nil values from
StructuredFactImporter) are excluded and handled individually.

Also initializes @counters with default zero values to prevent
potential nil access.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant