[POC] Optimize queries
WHY
BEFORE - What was wrong? What was happening before this PR?
Too many queries, some because of wrong eager loading, others because they were repeated in multiple places.
AFTER|HOW - What is happening after this PR?
I introduced a "transitory" cache that is flushed on every request (CrudPanel is a scoped singleton), or when any query produces changes in the database.
Mainly this will allow us to drastically reduce the number of queries, in combination with changes in (PRO PR https://github.com/Laravel-Backpack/PRO/pull/117).
Monster update page went from 120 queries to 40.
We can improve it further by having the "full tables" stored, since we would need the full list of models when using any select that's not ajax. But I left that to other PR, and to try to keep the scope of this one the smallest possible.
Is it a breaking change?
I don't think so, no.
How can we test the before & after?
Load the monster edit page (please fill one full monster with all relationships etc). You will see that 100+ queries are made. With this PR they should stay under 50 no matter how many entries you add in the relationships.
If the PR has changes in multiple repos please provide the command to checkout all branches, eg.:
cd vendor/backpack/crud && git checkout dev-optimize-queries &&
cd ../pro && git checkout dev-optimize-select-option &&
cd ../../..
The inspection completed: 3 new issues, 10 updated code elements