OpenEnergyDashboard / OED

Open Energy Dashboard (OED)
Mozilla Public License 2.0
75 stars 263 forks source link

changing unit rate does not update graphing values until refresh #1170

Open huss opened 6 months ago

huss commented 6 months ago

Describe the bug

If you update the rate on a flow unit that is currently being graphed in a line unit does not update the values on the graph (or Redux state). A web page refresh does show the new values.

To Reproduce

Steps to reproduce the behavior:

  1. Line graph of the Water Gallon flow 1-5 per minute.
  2. Go to units page, edit the Water_Gallon_Per_Minute unit and change rate from 60 to 600.
  3. Go back to line graphic and the values will not have changed.
  4. Refresh the web page and the values will be 1/10 what it was before and what was expected.

Additional context

I looked at this a little:

Given this, I'm unsure why the Redux state does not update but did not look in detail.

Rakesh-Ranga-Buram commented 1 month ago

@huss and I tried this and could not reproduce this error. Should do a final check to verify that this no longer exists.

huss commented 4 weeks ago

I tested this some more. If you wait at least several seconds after saving the unit after the rate change then it all works as desired. However, if you quickly go back to the line graphic page then OED crashes. In the console you see:

Screenshot 2024-08-31 081758

I have not debugged this but in the server console you see it is doing a DB refresh as it should when the unit rate changes. I would not be surprised if the issue might relate to the time it takes for that to happen (but am not sure). If so, this could be a more general issue. Does @ChrisMart21 have any ideas on this?

ChrisMart21 commented 4 weeks ago

Have not looked too deeply into this, however some thoughts: Notice that uiSelectors.ts - -SelectUnitCompatibility

https://github.com/OpenEnergyDashboard/OED/blob/development/src%2Fclient%2Fapp%2Fredux%2Fselectors%2FuiSelectors.ts#L31-L63

Calls methods from determinecompatibleunits.ts

https://github.com/OpenEnergyDashboard/OED/blob/development/src%2Fclient%2Fapp%2Futils%2FdetermineCompatibleUnits.ts#L5

SelectUnitCompatibility 'depends' on unit data, but it isn't in the dependency array for the selector. Which seems like it could be the issue when editing units

https://github.com/OpenEnergyDashboard/OED/blob/development/src%2Fclient%2Fapp%2Fredux%2Fselectors%2FuiSelectors.ts#L30-L37

determineCompatibleUnits.ts is importing store directly to do the computations which is bypassing the dependency array for the selector, and this selector is subsequently relied on by many other selectors for UI and graphing etc.. so this would be my first guess.

As for the app crashing, unless you wait a few seconds seems more bizarre to me. Not sure why it may be crashing, however the behavior @huss is describing seems like RTKQuery cache invalidating due to time spent unsubscribed from the query. Given a 'few seconds ' + the time it takes to navigate to the admin page /modify units seems like it would hit that 60 second unsubscribe cache invalidating trigger. When navigating back to the graphic page it would then cause a re-fetch instead of using the cache. Not sure why this would be the case, but invalidating graphic data on update may be an easy fix?

Perhaps fixing the selector issue would be a fix all,but not sure. Definitely something to look into though.