Clarify restart-safe batches and scripted UI handler tests

Address Nikola's batching and UI-handler feedback on PR #132. Preserve existing false-positive guards and defer the unconfirmed IsHandled policy.

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

Copilot-Session: f841a18b-535a-498e-96f2-f279b5378da5
This commit is contained in:
wenjiefan 2026-09-14 09:29:35 +02:00
parent 35d0966a8d
commit 0561b12c96
7 changed files with 155 additions and 46 deletions

View file

@ -1,26 +1,61 @@
query 50127 "Perf Customer Chunk"
{
QueryType = Normal;
OrderBy = ascending(CustomerNo);
elements
{
dataitem(Customer; Customer)
{
column(CustomerNo; "No.") { }
}
}
}
codeunit 50129 "Perf Sample CommitInLoop Bad"
{
procedure NormalizeCustomerNames()
procedure IncreaseCustomerCreditLimits()
var
LastCustomerNo: Code[20];
begin
while IncreaseNextChunk(LastCustomerNo) do
Commit();
end;
local procedure IncreaseNextChunk(var LastCustomerNo: Code[20]): Boolean
var
Customer: Record Customer;
LastCustomerNo: Code[20];
ProcessedCount: Integer;
TempCustomer: Record Customer temporary;
CustomerChunk: Query "Perf Customer Chunk";
ChunkStartedAt: DateTime;
MaxChunkDuration: Duration;
begin
Customer.SetFilter("No.", '>%1', LastCustomerNo);
if Customer.FindSet(true) then
ChunkStartedAt := CurrentDateTime();
MaxChunkDuration := 60000;
CustomerChunk.TopNumberOfRows(500);
if LastCustomerNo <> '' then
CustomerChunk.SetFilter(CustomerNo, '>%1', LastCustomerNo);
CustomerChunk.Open();
while CustomerChunk.Read() do begin
TempCustomer.Init();
TempCustomer."No." := CustomerChunk.CustomerNo;
TempCustomer.Insert();
end;
CustomerChunk.Close();
if TempCustomer.IsEmpty() then
exit(false);
Customer.LockTable();
if TempCustomer.FindSet() then
repeat
Customer.Name := UpperCase(Customer.Name);
Customer.Modify();
if Customer.Get(TempCustomer."No.") then begin
Customer."Credit Limit (LCY)" += 100;
Customer.Modify();
end;
LastCustomerNo := TempCustomer."No.";
until (TempCustomer.Next() = 0) or (CurrentDateTime() - ChunkStartedAt >= MaxChunkDuration);
// LastCustomerNo exists only in memory, so a retry cannot exclude
// work that was already committed.
LastCustomerNo := Customer."No.";
ProcessedCount += 1;
// This still opened a FindSet over the complete remaining tail;
// periodic commits do not turn retrieval into bounded TOP X.
if ProcessedCount mod 500 = 0 then
Commit();
until Customer.Next() = 0;
exit(true);
end;
}