-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Refactor: Make Load Balancer Optional Throughout Codebase #3860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Did you actually benchmark it? I suspect your reading of a config variable is actually orders of magnitude slower than the trivial LoadBalancer initialisation. For the second point, the queue is the Rust code's responsibility, and I don't think we should be exposing internal access to it. You can either do some operation that implicitly clears the queues (like |
If you're referring to the
I have mixed feelings about using db magic like |
^ Removed the |
Now we are cooking! After 785f88a this PR improves performance in comparison with main:
The final step is to agree on how to synchronize the config variable and the Win-win solution, in my opinion, will be to make the |
I'm afraid I think exposing a ClearStudyQueues RPC is the wrong approach here. I still think this too obscure an option to expose in the GUI, but I won't object to you adding it to GetPreferences/SetPreferences if you wish to do that instead. The GUI would ignore the extra field, but it could be updated in code. If you don't want to go that route, a routine that sets the option on or off is going to be cleanest. |
I'm not quite sure I understand your suggestion. Could you clarify what you mean by a "routine that sets the option on or off"? As mentioned earlier, the only way to reconstruct the |
The Rust code should be resetting the queues as the config option is changed. You can do this either by adding it to the preferences set/get code, or by creating a backend method set_load_balancer_enabled() that sets the config var and clears the queues at the same time. The caller in Python shouldn't need to know about the queues. |
I am unsure about the return types for |
You can make it undoable provided the queue resetting is done by adding that new operation to requires_study_queue_rebuild(), so queues are also reset when it's undone. This would be done instead of explicitly clearing them in the routine you've added. The return type should be the same as set_config_bool(). |
I considered using |
Thanks for your patience Yuki - looks good. For future reference, such import changes are fine, but please do them in a separate commit (in the same PR) to make things easier to review. |
Thank you for your thoughtful review and feedback on this PR! Your insights were extremely helpful. |
You added the following in ftl/core/actions.ftl (which is then used in rslib/src/ops.rs):
But is this string exposed somewhere in the ui? I wanted to edit the german translation in pontoon but wanted to see where the string is being used first. Edit: I built the latest code from main today. |
It appears when you undo the command:
|
Interesting. After following your first 2 steps, no undo action is registered in the edit menu. Ctrl+z doesn't do anything either. I tested it in a new profile as well, where Is this a bug? |
I see. Clicking on a deck afterwards does work. Edit: I opened an issue in #3918. |
The undo menus won't be updated automatically after running a command directly in the debug console. I overlooked the translation when merging in the PR - had I noticed, I would have suggested removing it, since it's a little silly to ask translators to translate something most people won't even see. |
This PR refactors the Load Balancer implementation to use
Option<LoadBalancer>
across the codebase, ensuring the Load Balancer is only instantiated when enabled. Previously, the Load Balancer was constructed even when disabled, incurring unnecessary overhead.Before this PR, only the
LoadBalancerContext
wasOptional
, so the mainLoadBalancer
object was still constructed on everybuild_queues
call, even with LB turned off (using themw.col.load_balancer_enabled = False
command).This PR makes all
LoadBalancer
objects optional.Key Changes:
LoadBalancer
:LoadBalancer
usage withOption<LoadBalancer>
in all relevant components (e.g.,CardQueues
,QueueBuilder
).LoadBalancer
initialization now depends on and is in sync with theload_balancer_enabled
configuration flag.ClearStudyQueues
ClearStudyQueues
RPC and corresponding backend method to reset study queues when toggling the Load Balancer. This prevents desynchronization between theload_balancer_enabled
flag and thecard_queues.load_balancer
state.mw.col.load_balancer_enabled = False
)card_queues
with an absentload_balancer
(None
)mw.col.load_balancer_enabled = True
)load_balancer
is absent in thecard_queues
because the queues weren't reloaded.load_balancer
are in sync. The newClearStudyQueues
RPC is invoked automatically when changingload_balancer_enabled
(viacollection.py
).