Skip to content

Commit 6192274

Browse files
MadinventorZerojonocrbuddhajjigaexkevinparkwilliamdyoon
committed
Fixed save frequency, projects now save on an interval of 15 seconds instead of after every state change. Should provide a solid performance boost and limit server requests.
Co-authored-by: jonocr <[email protected]> Co-authored-by: buddhajjigae <[email protected]> Co-authored-by: xkevinpark <[email protected]> Co-authored-by: williamdyoon <[email protected]>
1 parent fe3c094 commit 6192274

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

app/src/components/App.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,24 @@ export const App = (): JSX.Element => {
5757
}
5858
}, []);
5959

60-
useEffect(() => {
60+
// Caret this useEffect was triggering a save after every state change, which is bad for performance
61+
// useEffect(() => {
62+
// let userId;
63+
// if (Cookies.get('ssid')) {
64+
// userId = Cookies.get('ssid');
65+
// } else {
66+
// userId = window.localStorage.getItem('ssid');
67+
// }
68+
// if (state.isLoggedIn === false) {
69+
// localforage.setItem('guestProject', state);
70+
// } else if (state.name !== '') {
71+
// saveProject(state.name, state);
72+
// localforage.setItem(userId, state);
73+
// }
74+
// }, [state]);
75+
76+
// Caret setInterval alternative for 15 seconds between saves
77+
setInterval(() => {
6178
let userId;
6279
if (Cookies.get('ssid')) {
6380
userId = Cookies.get('ssid');
@@ -70,7 +87,7 @@ export const App = (): JSX.Element => {
7087
saveProject(state.name, state);
7188
localforage.setItem(userId, state);
7289
}
73-
}, [state]);
90+
}, 15000)
7491

7592
return (
7693
<div className="app">

0 commit comments

Comments
 (0)