Skip to content

Commit

Permalink
SetLoadFields, SetAutoCalcFields, IsEmtpy (microsoft#25084)
Browse files Browse the repository at this point in the history
We have some longrunning SQL Statements and Methods as well as Deadlocks
and Locktimeouts with the Headlines Executor.

I looked into it and found that there are possible optimizations for
example an IsEmpty before a deleteall, Calcfields in a Reapeat-Until
instead of SetAutoCalcFields and SetLoadFields on some older headline
procedures.

I would prefer a to add TopNumberOfRows at the TopCustomer Query, but
this would break the feature I think.
  • Loading branch information
BernhardKloibmueller authored Oct 30, 2023
1 parent 7d48712 commit 498a40a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ codeunit 1438 "Ess. Bus. Headline Subscribers"
exit;

EssentialBusinessHeadline.SetRange("User Id", UserSecurityId());
EssentialBusinessHeadline.DeleteAll();
if not EssentialBusinessHeadline.IsEmpty then
EssentialBusinessHeadline.DeleteAll();
end;

local procedure TransferHeadlineToPage(HeadlineName: Option; var HeadlineText: Text[250]; var HeadlineVisible: Boolean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ codeunit 1437 "Essential Bus. Headline Mgt."
exit;

BestQty := BestSoldItemQuery.SumQuantity;
Item.SetLoadFields(Description, "Base Unit of Measure");
Item.Get(BestSoldItemQuery.ProductNo);
HeadlineText := EssentialBusinessHeadline."Headline Text";

Expand All @@ -104,7 +105,8 @@ codeunit 1437 "Essential Bus. Headline Mgt."
EssentialBusinessHeadline."Headline Text" := CopyStr(HeadlineText, 1, MaxStrLen(EssentialBusinessHeadline."Headline Text"));
HeadlineDetails.SetRange(Type, HeadlineDetails.Type::Item);
HeadlineDetails.SetRange("User Id", UserSecurityId());
HeadlineDetails.DeleteAll();
if not HeadlineDetails.IsEmpty then
HeadlineDetails.DeleteAll();

InsertHeadlineDetails(BestSoldItemQuery.ProductNo, HeadlineDetails.Type::Item, Item.Description, Item."Base Unit of Measure", BestSoldItemQuery.SumQuantity, 0);

Expand Down Expand Up @@ -186,6 +188,7 @@ codeunit 1437 "Essential Bus. Headline Mgt."
if not BusiestResource.Read() then
exit;
BestQty := BusiestResource.SumQuantity;
Resource.SetLoadFields(Name, "Base Unit of Measure");
Resource.Get(BusiestResource.ProductNo);
HeadlineText := EssentialBusinessHeadline."Headline Text";

Expand All @@ -199,7 +202,8 @@ codeunit 1437 "Essential Bus. Headline Mgt."
EssentialBusinessHeadline."Headline Text" := CopyStr(HeadlineText, 1, MaxStrLen(EssentialBusinessHeadline."Headline Text"));
HeadlineDetails.SetRange(Type, HeadlineDetails.Type::Resource);
HeadlineDetails.SetRange("User Id", UserSecurityId());
HeadlineDetails.DeleteAll();
if not HeadlineDetails.IsEmpty then
HeadlineDetails.DeleteAll();

InsertHeadlineDetails(BusiestResource.ProductNo, HeadlineDetails.Type::Resource, Resource.Name, Resource."Base Unit of Measure", BusiestResource.SumQuantity, 0);

Expand Down Expand Up @@ -360,9 +364,8 @@ codeunit 1437 "Essential Bus. Headline Mgt."

// we need at least 5 sales for this headline to be valid
if (CustomerLedgerEntry.Count() > 5) then begin
CustomerLedgerEntry.SetAutoCalcFields(Amount);
if CustomerLedgerEntry.FindFirst() then begin
CustomerLedgerEntry.CalcFields(Amount);

if not Headlines.GetHeadlineText(
ChooseQualifier(QualifierWeekTxt, QualifierMonthTxt, Qualifier3MonthsTxt, DaysSearch),
StrSubstNo(LargestSalePayloadTxt,
Expand Down Expand Up @@ -506,6 +509,7 @@ codeunit 1437 "Essential Bus. Headline Mgt."
HeadlineText: Text;
begin
EssentialBusinessHeadline.GetOrCreateHeadline(EssentialBusinessHeadline."Headline Name"::RecentlyOverdueInvoices);
CustomerLedgerEntry.SetLoadFields(Open, "Due Date", "Document Type");
FindRecentlyOverdueInvoices(CustomerLedgerEntry, WorkDate());
RecentlyOverdueInvoices := CustomerLedgerEntry.Count();

Expand All @@ -516,9 +520,9 @@ codeunit 1437 "Essential Bus. Headline Mgt."
end;

TotalAmount := 0.0;
CustomerLedgerEntry.SetAutoCalcFields("Amount (LCY)");
if CustomerLedgerEntry.FindSet() then
repeat
CustomerLedgerEntry.CalcFields("Amount (LCY)");
TotalAmount := TotalAmount + CustomerLedgerEntry."Amount (LCY)";
until CustomerLedgerEntry.Next() = 0;

Expand Down Expand Up @@ -602,12 +606,10 @@ codeunit 1437 "Essential Bus. Headline Mgt."
if not TopCustomerHeadlineQuery.Read() then
exit;

Customer.Get(TopCustomerHeadlineQuery.CustomerNo);

HeadlineText := EssentialBusinessHeadline."Headline Text";
if not Headlines.GetHeadlineText(
ChooseQualifier(QualifierWeekTxt, QualifierMonthTxt, Qualifier3MonthsTxt, DaysSearch),
GetTopCustomerPayload(Customer.Name, FormatLocalCurrency(TopCustomerHeadlineQuery.SumAmountLcy)),
GetTopCustomerPayload(TopCustomerHeadlineQuery.CustomerName, FormatLocalCurrency(TopCustomerHeadlineQuery.SumAmountLcy)),
HeadlineText)
then
exit;
Expand All @@ -616,7 +618,8 @@ codeunit 1437 "Essential Bus. Headline Mgt."
EssentialBusinessHeadline."Headline Text" := CopyStr(HeadlineText, 1, MaxStrLen(EssentialBusinessHeadline."Headline Text"));
HeadlineDetails.SetRange(Type, HeadlineDetails.Type::Customer);
HeadlineDetails.SetRange("User Id", UserSecurityId());
HeadlineDetails.DeleteAll();
if not HeadlineDetails.IsEmpty then
HeadlineDetails.DeleteAll();
InsertHeadlineDetails(TopCustomerHeadlineQuery.No, HeadlineDetails.Type::Customer, TopCustomerHeadlineQuery.CustomerName, '', 0, TopCustomerHeadlineQuery.SumAmountLcy);

// if there is only one customer last month, do not set to visible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ query 1440 "Best Sold Item Headline"
{
QueryType = Normal;
OrderBy = descending(SumQuantity);
DataAccessIntent = ReadOnly;

elements
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using Microsoft.Sales.History;
query 1442 "Sales Increase Headline"
{
QueryType = Normal;
DataAccessIntent = ReadOnly;

elements
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ query 1441 "Top Customer Headline"
{
QueryType = Normal;
OrderBy = descending(SumAmountLcy);
DataAccessIntent = ReadOnly;

elements
{
Expand Down

0 comments on commit 498a40a

Please sign in to comment.