From 930cb17848e47419861c373a8613d46a0da67219 Mon Sep 17 00:00:00 2001 From: Alexis Date: Mon, 20 Sep 2021 14:10:19 +0930 Subject: [PATCH] fix: pre-fill user server cache on start --- app/mothership/index.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/mothership/index.ts b/app/mothership/index.ts index 0004dd08f..38cb12a3b 100644 --- a/app/mothership/index.ts +++ b/app/mothership/index.ts @@ -9,6 +9,8 @@ import packageJson from '../../package.json'; import { paths } from '../core/paths'; import { loadState } from '../core/utils/misc/load-state'; import { subscribeToServers } from './subscribe-to-servers'; +import { getServers as getUserServers } from '../utils'; +import { CachedServers, userCache } from '../cache/user'; export const sockets = { internal: null as GracefulWebSocket | null, @@ -44,6 +46,22 @@ export const startInternal = (apiKey: string) => { // Internal is ready at this point startRelay(); + + // Pre-fill local cache + getUserServers(apiKey).then(servers => { + // Bail if no servers are returned + if (!servers) { + return; + } + + // Cache servers + userCache.set('mine', { + servers + }); + }).catch(error => { + log.debug('Failed fetching user\'s servers with "%s".', error.message); + }); + subscribeToServers(apiKey); });