jaspy2 / jaspy

MIT License
8 stars 4 forks source link

Switchmaster UI should send only changed data #20

Open atonkyra opened 4 years ago

atonkyra commented 4 years ago

Switchmaster currently sends full object when updating configured->unconfigured (or vice versa) or when updating the switch location.

This leads to a race where user1 changes switch to unconfigured. Simultaneously user2 changes switch from stationed to at storage which overwrites the unconfigured state back to configured since user2 did not (yet) get the statechange by user1.

Last commit wins when manipulating the same value but the manipulation must be scoped to the value that is being changed and not to the whole "switch" object.

atonkyra commented 4 years ago

Issue can be (temporarily) worked around using following patch pending final fix.

diff --git a/switchmaster/src/Jaspy.Switchmaster/ClientApp/src/components/SwitchStatePanel.vue b/switchmaster/src/Jaspy.Switchmaster/ClientApp/src/components/SwitchStatePanel.vue
index 5327030..d3d14ed 100644
--- a/switchmaster/src/Jaspy.Switchmaster/ClientApp/src/components/SwitchStatePanel.vue
+++ b/switchmaster/src/Jaspy.Switchmaster/ClientApp/src/components/SwitchStatePanel.vue
@@ -96,17 +96,15 @@ export default class SwitchStatePanel extends Vue {
                 throw Error('Invalid deploy state during update.');
         }

-        await this.updateItem({
+        await this.updateItem(<any>{
             fqdn: this.fqdn,
-            deployState: newState,
-            configured: !!this.isConfigured
+            deployState: newState
         });
     }

     public async toggleConfigured() {
-        await this.updateItem({
+        await this.updateItem(<any>{
             fqdn: this.fqdn,
-            deployState: this.deployState,
             configured: !this.isConfigured
         });
     }