Best practice for ui_switch

I have tenths of ui_switches in my Dashboard, controlled by mqtt (the switch is set as "Switch icon shows state of the input"), schematically represented by this flow:

Now, when I need to restart NR, all the ui_switches go into an undetermined state, so in order to get the state of the switch I am modifying those flows with this one (saving a flow variable):

Is this the best practice? With this modified flow, each time I start the Dashboard I have a peak of CPU consumption .

There are a few ways to do this, you could have an inject node set to trigger once at startup instead of ui_control, since the ui_conrol may be triggering when not needed eg change tab etc.

Or you could set the mqtt in messages to be retained so they get re-sent when when NR restarts.

But do you really need to restart NR that often ? Have you tried only deploying changed nodes ?

Indeed, I don't need to restart so often. But when it happens, I lose the status of too many devices...I have tried with the inject node to trigger at startup, but it seems not always working.