Refactor controller insert code to be cleaner and do less work
While looking at item voiding bugs, etc, i noticed the logic around inserts into controllers seemed in need of a bit of a refactor. The way it is currently structured does tests a bunch of times on the same drawers, can't exit early because of how it marks drawers for rebalancing, etc.
This refactors the code to hopefully be clearer, cleaner, and does strictly the same or less work than the old code.
For primary records: First we gather the valid non-empty drawers that meet the predicates, and drawers that would need rebalancing if we place an item. Then we go over these drawers , once with the strict check, and if needed, with the loose check. If we placed an item in a balance-fill drawer, we mark the need to rebalance all the balance-fill drawers. If we run out of items to place, we stop.
If we still have to place anything - we walk the drawer slots, and place items into the enabled ones.
Note that the latter loop did not ever rebalance drawers marked as balanced-fill even if items were placed. I believe this is a bug in theory (if primaryrecords is null, we will never rebalance), and it is easy to fix, but i left the logic as-is for now until someone smarter than me thinks about it :). Happy to fix it if it is a bug.
The split diff is much easier to read than the unified.