@@ -81,6 +81,8 @@ qx.Class.define("osparc.desktop.StudyEditor", {
8181 } ) ;
8282
8383 this . __updatingStudy = 0 ;
84+ this . __lastPatchTime = 0 ;
85+ this . __throttledPendingUpdate = false ;
8486 } ,
8587
8688 events : {
@@ -106,6 +108,7 @@ qx.Class.define("osparc.desktop.StudyEditor", {
106108 statics : {
107109 AUTO_SAVE_INTERVAL : 3000 ,
108110 DIFF_CHECK_INTERVAL : 300 ,
111+ THROTTLE_PATCH_TIME : 1000 ,
109112 READ_ONLY_TEXT : qx . locale . Manager . tr ( "You do not have writing permissions.<br>Your changes will not be saved." ) ,
110113 } ,
111114
@@ -121,6 +124,8 @@ qx.Class.define("osparc.desktop.StudyEditor", {
121124 __updatingStudy : null ,
122125 __updateThrottled : null ,
123126 __nodesSlidesTree : null ,
127+ __lastPatchTime : null ,
128+ __throttledPendingUpdate : null ,
124129
125130 setStudyData : function ( studyData ) {
126131 if ( this . __settingStudy ) {
@@ -904,14 +909,30 @@ qx.Class.define("osparc.desktop.StudyEditor", {
904909 } ,
905910
906911 /**
907- * @param {JSON Patch } data It will soon be used to patch the study document https://datatracker.ietf.org/doc/html/rfc6902
912+ * @param {JSON Patch } data It will soon be used to patch the project document https://datatracker.ietf.org/doc/html/rfc6902
908913 */
909914 projectDocumentChanged : function ( data ) {
915+ data [ "userGroupId" ] = osparc . auth . Data . getInstance ( ) . getGroupId ( ) ;
910916 if ( osparc . utils . Utils . isDevelopmentPlatform ( ) ) {
911917 console . log ( "projectDocumentChanged" , data ) ;
912918 }
913919
914- this . updateStudyDocument ( ) ;
920+ // throttling: do not update study document right after a change, wait for THROTTLE_PATCH_TIME
921+ const throttlePatchTime = this . self ( ) . THROTTLE_PATCH_TIME ;
922+ const now = Date . now ( ) ;
923+ const timeSinceLastUpdate = now - this . __lastPatchTime ;
924+ if ( timeSinceLastUpdate >= throttlePatchTime ) {
925+ this . updateStudyDocument ( ) ;
926+ this . __lastPatchTime = now ;
927+ } else if ( ! this . __throttledPendingUpdate ) {
928+ // Otherwise, schedule a call after remaining time
929+ this . __throttledPendingUpdate = true ;
930+ setTimeout ( ( ) => {
931+ this . updateStudyDocument ( ) ;
932+ this . __lastPatchTime = Date . now ( ) ;
933+ this . __throttledPendingUpdate = false ;
934+ } , throttlePatchTime - timeSinceLastUpdate ) ;
935+ }
915936 } ,
916937
917938 updateStudyDocument : function ( ) {
0 commit comments