Debouncing updates from the worker to the main thread (this was crashing the app during heavy syncs).
This commit is contained in:
1 parent
4b55763a03
commit
91916fca88
1 file changed
+12
-2
@@ -1,4 +1,4 @@
|
|||||||
import { slice } from 'lodash';
|
import { debounce, slice } from 'lodash';
|
||||||
import { getWpt } from '../db/wpt';
|
import { getWpt } from '../db/wpt';
|
||||||
import { returnAgain } from '../workers/dispatcher-worker';
|
import { returnAgain } from '../workers/dispatcher-worker';
|
||||||
import { getAllGpxes, getGpx } from './gpx';
|
import { getAllGpxes, getGpx } from './gpx';
|
||||||
@@ -31,6 +31,15 @@ const sendUpdate = async (params: any) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let debouncedSendUpdates = <any>{};
|
||||||
|
|
||||||
|
for (const property in methods) {
|
||||||
|
debouncedSendUpdates[<keyof typeof debouncedSendUpdates>property] = debounce(
|
||||||
|
sendUpdate,
|
||||||
|
500
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const changeHandler = async (change: any) => {
|
const changeHandler = async (change: any) => {
|
||||||
console.log({ caller: 'ChangeHandler', change, watches: globalThis.watches });
|
console.log({ caller: 'ChangeHandler', change, watches: globalThis.watches });
|
||||||
const { id } = change;
|
const { id } = change;
|
||||||
@@ -69,7 +78,8 @@ const changeHandler = async (change: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendUpdate(globalThis.watches.get(parentId));
|
const parentParams = globalThis.watches.get(parentId);
|
||||||
|
debouncedSendUpdates[parentParams.method](parentParams);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default changeHandler;
|
export default changeHandler;
|
||||||
|
|||||||
Reference in new issue
Block a user