bcquality/microsoft/knowledge/performance/split-read-only-and-write-paths-to-avoid-locktable.good.al
Jesper Schulz-Wedde 5bcdc55df9 Sync knowledge articles with review agent instructions
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-05 14:08:32 +02:00

18 lines
577 B
AL

codeunit 51204 "Perf Sample LockTable Good"
{
procedure GetOrCreate(var AgentStatus: Record "Integer"): Boolean
begin
// Read path: consistent read on this record instance only.
AgentStatus.ReadIsolation := IsolationLevel::ReadCommitted;
if AgentStatus.Get(1) then
exit(true);
// Write path: lock only when we are about to insert.
AgentStatus.LockTable();
if not AgentStatus.Get(1) then begin
AgentStatus.Number := 1;
AgentStatus.Insert();
end;
exit(true);
end;
}