Forced cache updating on application initialization or closing (#4297)
This commit is contained in:
parent
e2a3e8538a
commit
6d21e75efa
@ -44,7 +44,8 @@ import { isHeavyAnimating } from '../hooks/useHeavyAnimationCheck';
|
|||||||
|
|
||||||
const UPDATE_THROTTLE = 5000;
|
const UPDATE_THROTTLE = 5000;
|
||||||
|
|
||||||
const updateCacheThrottled = throttle(() => onIdle(updateCache), UPDATE_THROTTLE, false);
|
const updateCacheThrottled = throttle(() => onIdle(() => updateCache()), UPDATE_THROTTLE, false);
|
||||||
|
const updateCacheForced = () => updateCache(true);
|
||||||
|
|
||||||
let isCaching = false;
|
let isCaching = false;
|
||||||
let unsubscribeFromBeforeUnload: NoneToVoidFunction | undefined;
|
let unsubscribeFromBeforeUnload: NoneToVoidFunction | undefined;
|
||||||
@ -70,6 +71,7 @@ export function initCache() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setupCaching();
|
setupCaching();
|
||||||
|
updateCacheForced();
|
||||||
});
|
});
|
||||||
|
|
||||||
addActionHandler('reset', resetCache);
|
addActionHandler('reset', resetCache);
|
||||||
@ -95,15 +97,15 @@ export function loadCache(initialState: GlobalState): GlobalState | undefined {
|
|||||||
|
|
||||||
export function setupCaching() {
|
export function setupCaching() {
|
||||||
isCaching = true;
|
isCaching = true;
|
||||||
unsubscribeFromBeforeUnload = onBeforeUnload(updateCache, true);
|
unsubscribeFromBeforeUnload = onBeforeUnload(updateCacheForced, true);
|
||||||
window.addEventListener('blur', updateCache);
|
window.addEventListener('blur', updateCacheForced);
|
||||||
addCallback(updateCacheThrottled);
|
addCallback(updateCacheThrottled);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearCaching() {
|
export function clearCaching() {
|
||||||
isCaching = false;
|
isCaching = false;
|
||||||
removeCallback(updateCacheThrottled);
|
removeCallback(updateCacheThrottled);
|
||||||
window.removeEventListener('blur', updateCache);
|
window.removeEventListener('blur', updateCacheForced);
|
||||||
if (unsubscribeFromBeforeUnload) {
|
if (unsubscribeFromBeforeUnload) {
|
||||||
unsubscribeFromBeforeUnload();
|
unsubscribeFromBeforeUnload();
|
||||||
}
|
}
|
||||||
@ -221,9 +223,9 @@ function unsafeMigrateCache(cached: GlobalState, initialState: GlobalState) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateCache() {
|
function updateCache(force?: boolean) {
|
||||||
const global = getGlobal();
|
const global = getGlobal();
|
||||||
if (!isCaching || global.isLoggingOut || isHeavyAnimating()) {
|
if (!isCaching || global.isLoggingOut || (!force && isHeavyAnimating())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user