Skip to content

knowledge(performance): Get behind a key-is-set check in and-condition wastes a DB call - #275

Draft
Kilian Seizinger (pri-kise) wants to merge 1 commit into
microsoft:mainfrom
pri-kise:get-behind-key-check-performance
Draft

Kilian Seizinger (pri-kise) wants to merge 1 commit into
microsoft:mainfrom
pri-kise:get-behind-key-check-performance

Conversation

@pri-kise

Copy link
Copy Markdown
Contributor

Was

Erweitert boolean-operators-do-not-short-circuit um den Fall, dass Record.Get(...) der abhängige Operand hinter einer Key-Prüfung ist:

if (EntryNo <> 0) and Rec.Get(EntryNo) then exit(Rec.Field); exit('');

Das ist nicht unsicher, schickt aber bei EntryNo = 0 jedes Mal eine Datenbankabfrage, die nichts finden kann. Es geht um Performance, nicht um Korrektheit.

Änderungen

  • Best Practice: Guard Clause zuerst (if EntryNo = 0 then exit('')), Get erst danach.
  • Anti Pattern: neues Erkennungssignal für Rec.Get(Key) hinter Key <> 0 bzw. Key <> '', wenn nur ein Feldwert oder Default zurückgegeben wird.
  • Samples: GetEntryDescription in .bad.al und .good.al.

Keine neue Datei, weil die Regel das Muster bereits abdeckt und sonst ein Duplikat entstünde.

Prüfung

Test-ReviewFixtures.ps1 läuft durch.

…n wastes a DB call

Extend the no-short-circuit rule with the case where Rec.Get is the dependent operand behind a Key <> 0 / '' check and only a field value or default is returned: nothing breaks, but every call with an unset key sends a query that cannot find a record. Add GetEntryDescription to the bad/good samples.
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.

1 participant