[28.x] Subscription Billing: O(N²) contract-renewal detection in Sales-Post subscribers slows posting (~28% of batch CPU) - #9567
Conversation
|
Agentic PR Review - Round 1Recommendation: Request ChangesWhat this PR doesThis PR replaces repeated SalesLine.IsContractRenewal() and SalesHeader.HasOnlyContractRenewalLines() calls in Sales-Post subscribers with cached wrappers, and clears the caches on OnBeforePostSalesDoc and OnAfterPostSalesDoc. The change targets the AB#642309 performance issue and should remove repeated per-line full-document scans. I verified the new subscribers hook into existing BaseApp publisher events (SalesPost.Codeunit.al in src/Layers/*/BaseApp/Sales/Posting) and the null-SystemId fallback keeps behavior for temporary buffers. SuggestionsS1 - Add regression test for cache reset boundaries Risk assessment and necessityRisk: The touched path is Sales posting, so a cache mistake can silently skip invoice/shipment line insertion or header creation. The code is targeted to one codeunit, but the event subscribers are in a financially sensitive flow. Necessity: The work item describes a real and costly performance problem (~25-28% of batch CPU in renewal detection), so optimization is justified. Without this change, large invoice batch posting remains unnecessarily slow and has no practical workaround.
|
Fixes AB#642309