Skip to content

Add v_total_direct_service_children virtual total to Service model - #23995

Merged
Fryguy merged 3 commits into
ManageIQ:masterfrom
GilbertCherrie:add-v-total-direct-service-children-virtual-total
Oct 2, 2026
Merged

Fryguy merged 3 commits into
ManageIQ:masterfrom
GilbertCherrie:add-v-total-direct-service-children-virtual-total

Conversation

@GilbertCherrie

@GilbertCherrie GilbertCherrie commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

This PR is required for: ManageIQ/manageiq-ui-service#2215 and ManageIQ/manageiq-api#1345

Add v_total_direct_service_children virtual total to Service

Adds a new SQL-backed virtual total v_total_direct_service_children to the Service model that counts the number of direct (first-level) service children for a given service record.

What it does:

Uses an Arel subquery against the services table to count child records whose ancestry exactly matches the current record's ancestry path
Handles both root services (no ancestry) and nested services (with ancestry) via a CASE expression
Returns 0 (via COALESCE) when no direct children exist
Supports SQL-level evaluation (via SELECT) and falls back to Ruby-level evaluation

Tests added:

SQL path: verifies v_total_direct_service_children is populated correctly when selected via Service.select(:id, :v_total_direct_service_children)
Ruby path: verifies the attribute is computed in Ruby when not SQL-selected, and confirms attribute_present? returns false in that case

@GilbertCherrie

Copy link
Copy Markdown
Member Author

@miq-bot assign @jrafanie
@miq-bot add-label enhancement

@@ -545,6 +545,32 @@
end
end

describe "#v_total_direct_service_children" do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"direct" in our parlance means "directly under the service", so in the example tree below there are only 2 direct service children, c1, and c2. Are you looking for all service children (i.e. the entire tree?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok yeah - spoke with @GilbertCherrie and that is what this is doing - the test didn't make that clear to me.

@GilbertCherrie

Copy link
Copy Markdown
Member Author

@miq-bot add-label tal/yes?

@GilbertCherrie
GilbertCherrie force-pushed the add-v-total-direct-service-children-virtual-total branch from c2bc6ad to 8b48ed8 Compare October 2, 2026 18:36
@Fryguy

Fryguy commented Oct 2, 2026

Copy link
Copy Markdown
Member

I'm going to merge this as is, however I want to follow up with the ancestry gem and see if we can find a way to expose it there instead, because it's really a concern for that gem. Spoke to @kbrock about it briefly, and he agreed, though we're not actually sure how to structure that, hence merging this as is.

@miq-bot

miq-bot commented Oct 2, 2026

Copy link
Copy Markdown
Member

Checked commits GilbertCherrie/manageiq@b34a429~...8b48ed8 with ruby 3.3.12, rubocop 1.91.0, haml-lint 0.78.0, and yamllint 1.37.1
2 files checked, 0 offenses detected
Everything looks fine. 🍪

@Fryguy
Fryguy merged commit 27efecc into ManageIQ:master Oct 2, 2026
6 checks passed
@GilbertCherrie
GilbertCherrie deleted the add-v-total-direct-service-children-virtual-total branch October 5, 2026 13:40
@Fryguy Fryguy added tal/yes and removed tal/yes? labels Oct 7, 2026
@Fryguy

Fryguy commented Oct 7, 2026

Copy link
Copy Markdown
Member

Backported to tal in commit c519f17.

commit c519f17296a5ff26e43e6fb6c25579dfece15f6b
Author: Jason Frey <fryguy9@gmail.com>
Date:   Fri Oct 2 18:26:37 2026 -0400

    Merge pull request #23995 from GilbertCherrie/add-v-total-direct-service-children-virtual-total
    
    Add v_total_direct_service_children virtual total to Service model
    
    (cherry picked from commit 27efeccb539d22e625455f4bd7df4853a153cc7b)

Fryguy added a commit that referenced this pull request Oct 7, 2026
…ice-children-virtual-total

Add v_total_direct_service_children virtual total to Service model

(cherry picked from commit 27efecc)
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.

4 participants