Skip to content

Optimize SalesHead_Has_PurchaseOrdreNo performance - #98

Open
PropmanProphecy with Copilot wants to merge 1 commit into
mainfrom
perf/saleshead-has-purchaseordreno
Open

PropmanProphecy with Copilot wants to merge 1 commit into
mainfrom
perf/saleshead-has-purchaseordreno

Conversation

Copilot AI commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Problem

The CPU profile showed SalesHead_Has_PurchaseOrdreNo as a hotspot. It looped over every Sales Line of a header and ran a separate SELECT TOP 1 on Purchase Line for each item line. The procedure is called per row from the Sales Order List, Quotes, Return Order List and Credit Memos pages (N+1 queries).

Change

Replaced the loop with a single IsEmpty() check on Purchase Line, using the existing key (Sales Order No., Sales Order Line No.) filtered on Sales Order No..

Notes

  • Behaviour change: the old code only counted purchase lines linked to Item-type sales lines; the new check counts any purchase line carrying the sales order number.
  • Not built or tested.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants