mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-11-02 06:13:11 +08:00
feat: return cached result
This commit is contained in:
@@ -132,12 +132,13 @@ function assertRelease() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let lastChecking = Date.now();
|
let lastChecking = Date.now();
|
||||||
|
let lastResult:CheckResult;
|
||||||
export async function checkUpdate(APPKEY: string, isRetry?: boolean) {
|
export async function checkUpdate(APPKEY: string, isRetry?: boolean) {
|
||||||
assertRelease();
|
assertRelease();
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (now - lastChecking < 1000 * 5) {
|
if (lastResult && now - lastChecking < 1000 * 60) {
|
||||||
logger('repeated checking, ignored');
|
logger('repeated checking, ignored');
|
||||||
return;
|
return lastResult;
|
||||||
}
|
}
|
||||||
lastChecking = now;
|
lastChecking = now;
|
||||||
if (blockUpdate && blockUpdate.until > Date.now() / 1000) {
|
if (blockUpdate && blockUpdate.until > Date.now() / 1000) {
|
||||||
@@ -177,6 +178,7 @@ export async function checkUpdate(APPKEY: string, isRetry?: boolean) {
|
|||||||
return checkUpdate(APPKEY, true);
|
return checkUpdate(APPKEY, true);
|
||||||
}
|
}
|
||||||
const result: CheckResult = await resp.json();
|
const result: CheckResult = await resp.json();
|
||||||
|
lastResult = result;
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
checkOperation(result.op);
|
checkOperation(result.op);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user