How to deal with repeated database calls on forms

Just wondering....how do you chose to avoid repeated database calls when making dynamic forms? For example, take a form that collects payment data for invoices. The select at the top gets the invoice number, and then a number of placeholders with information are driven off that. Including things like invoice lines etc. Then the form checks the payment amount entered and uses a placeholder warning if that doesn't match the invoice balance. I end up with the Invoice model being repeatedly called in various ->visible functions, and for placeholder dynamic text. What's the best approach to limiting these database calls only to when we need to, like the selection of invoice changes?
1 Reply
Dennis Koch
Dennis Koch17h ago
I usually use memoization for stuff like this. Or extract to a method that returns once(fn () => get model)

Did you find this page helpful?