Don't fetch remote config twice on startup
This commit is contained in:
parent
24391af642
commit
1b0de9d7bd
3 changed files with 26 additions and 19 deletions
|
@ -65,11 +65,6 @@ export function restoreRemoteConfigFromStorage(): void {
|
|||
config = window.storage.get('remoteConfig') || {};
|
||||
}
|
||||
|
||||
export async function initRemoteConfig(server: WebAPIType): Promise<void> {
|
||||
restoreRemoteConfigFromStorage();
|
||||
await maybeRefreshRemoteConfig(server);
|
||||
}
|
||||
|
||||
export function onChange(
|
||||
key: ConfigKeyType,
|
||||
fn: ConfigListenerType
|
||||
|
@ -83,7 +78,7 @@ export function onChange(
|
|||
};
|
||||
}
|
||||
|
||||
export const refreshRemoteConfig = async (
|
||||
export const _refreshRemoteConfig = async (
|
||||
server: WebAPIType
|
||||
): Promise<void> => {
|
||||
const now = Date.now();
|
||||
|
@ -93,7 +88,7 @@ export const refreshRemoteConfig = async (
|
|||
|
||||
if (Math.abs(serverTimeSkew) > HOUR) {
|
||||
log.warn(
|
||||
'Remote Config: sever clock skew detected. ' +
|
||||
'Remote Config: severe clock skew detected. ' +
|
||||
`Server time ${serverTimestamp}, local time ${now}`
|
||||
);
|
||||
}
|
||||
|
@ -154,12 +149,21 @@ export const refreshRemoteConfig = async (
|
|||
};
|
||||
|
||||
export const maybeRefreshRemoteConfig = throttle(
|
||||
refreshRemoteConfig,
|
||||
_refreshRemoteConfig,
|
||||
// Only fetch remote configuration if the last fetch was more than two hours ago
|
||||
2 * 60 * 60 * 1000,
|
||||
{ trailing: false }
|
||||
);
|
||||
|
||||
export async function forceRefreshRemoteConfig(
|
||||
server: WebAPIType,
|
||||
reason: string
|
||||
): Promise<void> {
|
||||
log.info(`forceRefreshRemoteConfig: ${reason}`);
|
||||
maybeRefreshRemoteConfig.cancel();
|
||||
await _refreshRemoteConfig(server);
|
||||
}
|
||||
|
||||
export function isEnabled(name: ConfigKeyType): boolean {
|
||||
return get(config, [name, 'enabled'], false);
|
||||
}
|
||||
|
|
|
@ -400,7 +400,9 @@ export async function startApp(): Promise<void> {
|
|||
}
|
||||
return server.getSocketStatus();
|
||||
};
|
||||
|
||||
let accountManager: AccountManager;
|
||||
let isInRegistration = false;
|
||||
window.getAccountManager = () => {
|
||||
if (accountManager) {
|
||||
return accountManager;
|
||||
|
@ -411,12 +413,14 @@ export async function startApp(): Promise<void> {
|
|||
|
||||
accountManager = new window.textsecure.AccountManager(server);
|
||||
accountManager.addEventListener('startRegistration', () => {
|
||||
isInRegistration = true;
|
||||
pauseProcessing();
|
||||
|
||||
backupReady.reject(new Error('startRegistration'));
|
||||
backupReady = explodePromise();
|
||||
});
|
||||
accountManager.addEventListener('registration', () => {
|
||||
isInRegistration = false;
|
||||
window.Whisper.events.trigger('userChanged', false);
|
||||
|
||||
drop(Registration.markDone());
|
||||
|
@ -1038,8 +1042,6 @@ export async function startApp(): Promise<void> {
|
|||
}
|
||||
});
|
||||
|
||||
void window.Signal.RemoteConfig.initRemoteConfig(server);
|
||||
|
||||
const retryPlaceholders = new RetryPlaceholders({
|
||||
retryReceiptLifespan: HOUR,
|
||||
});
|
||||
|
@ -1489,10 +1491,6 @@ export async function startApp(): Promise<void> {
|
|||
|
||||
strictAssert(server !== undefined, 'WebAPI not ready');
|
||||
|
||||
// Cancel throttled calls to refreshRemoteConfig since our auth changed.
|
||||
window.Signal.RemoteConfig.maybeRefreshRemoteConfig.cancel();
|
||||
drop(window.Signal.RemoteConfig.maybeRefreshRemoteConfig(server));
|
||||
|
||||
drop(connect(true));
|
||||
|
||||
// Connect messageReceiver back to websocket
|
||||
|
@ -1594,7 +1592,9 @@ export async function startApp(): Promise<void> {
|
|||
const onOnline = () => {
|
||||
log.info('background: online');
|
||||
|
||||
if (!remotelyExpired) {
|
||||
// Do not attempt to connect while expired or in-the-middle of
|
||||
// registration
|
||||
if (!remotelyExpired && !isInRegistration) {
|
||||
drop(connect());
|
||||
}
|
||||
};
|
||||
|
@ -1848,11 +1848,14 @@ export async function startApp(): Promise<void> {
|
|||
drop(AttachmentBackupManager.start());
|
||||
}
|
||||
|
||||
if (connectCount === 0) {
|
||||
if (connectCount === 0 || firstRun) {
|
||||
try {
|
||||
// Force a re-fetch before we process our queue. We may want to turn on
|
||||
// something which changes how we process incoming messages!
|
||||
await window.Signal.RemoteConfig.refreshRemoteConfig(server);
|
||||
await window.Signal.RemoteConfig.forceRefreshRemoteConfig(
|
||||
server,
|
||||
`connectCount=${connectCount} firstRun=${firstRun}`
|
||||
);
|
||||
|
||||
const expiration = window.Signal.RemoteConfig.getValue(
|
||||
'desktop.clientExpiration'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { refreshRemoteConfig } from '../../RemoteConfig';
|
||||
import { _refreshRemoteConfig } from '../../RemoteConfig';
|
||||
import type {
|
||||
WebAPIType,
|
||||
RemoteConfigResponseType,
|
||||
|
@ -16,5 +16,5 @@ export async function updateRemoteConfig(
|
|||
},
|
||||
} as Partial<WebAPIType> as unknown as WebAPIType;
|
||||
|
||||
await refreshRemoteConfig(fakeServer);
|
||||
await _refreshRemoteConfig(fakeServer);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue