Skip to content

Commit

Permalink
improved performance due to optimizations on auto save
Browse files Browse the repository at this point in the history
- closes #121
  • Loading branch information
foxriver76 committed Nov 6, 2023
1 parent 5ce7d1c commit fa30684
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ E.g., if it was used in a menu and the menu is red, the circle would be red.
### **WORK IN PROGRESS**
-->
## Changelog

### **WORK IN PROGRESS**
* (foxriver76) improved performance due to optimizations on auto save

### 2.3.5 (2023-11-03)
* (foxriver76) update adapter-react to have enhanced image support in file selector
* (foxriver76) fixed color of file browser in light mode
Expand Down
28 changes: 13 additions & 15 deletions src/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -988,42 +988,40 @@ class App extends Runtime {
}

changeProject = async (project, ignoreHistory) => {
// remove all special structures
this.unsyncMultipleWidgets(project);

// set timestamp
project.___settings.ts = `${Date.now()}.${Math.random().toString(36).substring(7)}`;
const newState = { project, needSave: true };

if (!ignoreHistory) {
// do not save history too often
this.saveHistory(project);
}

const projectStr = JSON.stringify(project, null, 2);
await this.setStateAsync({ visProject: project, needSave: true });

// save changes after 1 second
// eslint-disable-next-line no-unused-expressions
this.savingTimer && clearTimeout(this.savingTimer);
this.savingTimer = setTimeout(async _projectStr => {
this.savingTimer = setTimeout(async () => {
console.log('save');
this.savingTimer = null;

// remove all special structures
this.unsyncMultipleWidgets(project);

const projectStr = JSON.stringify(project, null, 2);

if ('TextEncoder' in window) {
const encoder = new TextEncoder();
const data = encoder.encode(_projectStr);
const data = encoder.encode(projectStr);
await this.socket.writeFile64(this.adapterId, `${this.state.projectName}/vis-views.json`, data);
} else {
await this.socket.writeFile64(this.adapterId, `${this.state.projectName}/vis-views.json`, _projectStr);
await this.socket.writeFile64(this.adapterId, `${this.state.projectName}/vis-views.json`, projectStr);
}

this.setState({ needSave: false });
if (this.needRestart) {
window.location.reload();
}
}, 1000, projectStr);

this.syncMultipleWidgets(project);

newState.visProject = project;
await this.setStateAsync(newState);
}, 1_000);
};

unsyncMultipleWidgets(project) {
Expand Down

0 comments on commit fa30684

Please sign in to comment.