Skip to content

Conversation

@dberlin
Copy link

@dberlin dberlin commented Dec 18, 2025

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.

@dberlin dberlin changed the title Stop checking drawers when we run out of items to fit in them Refactor controller insert code to be cleaner and do less work Dec 18, 2025
@dberlin dberlin force-pushed the blockControllerInsertChecking branch from e7a428d to d41b55f Compare December 18, 2025 15:07
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