Remove KVStore / localforage cache

This commit is contained in:
Alex Gleason 2024-11-27 23:00:40 -06:00
parent 55ef41f1a5
commit 269de213d1
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
9 changed files with 5 additions and 120 deletions

View File

@ -113,7 +113,6 @@
"leaflet": "^1.8.0",
"lexical": "^0.18.0",
"line-awesome": "^1.3.0",
"localforage": "^1.10.0",
"lodash": "^4.7.11",
"mini-css-extract-plugin": "^2.6.0",
"nostr-tools": "^2.3.0",

View File

@ -18,7 +18,6 @@ import { custom } from 'soapbox/custom.ts';
import { queryClient } from 'soapbox/queries/client.ts';
import { selectAccount } from 'soapbox/selectors/index.ts';
import { unsetSentryAccount } from 'soapbox/sentry.ts';
import KVStore from 'soapbox/storage/kv-store.ts';
import toast from 'soapbox/toast.tsx';
import { getLoggedInAccount, parseBaseURL } from 'soapbox/utils/auth.ts';
import sourceCode from 'soapbox/utils/code.ts';
@ -164,23 +163,6 @@ export const verifyCredentials = (token: string, accountUrl?: string) => {
};
};
export const rememberAuthAccount = (accountUrl: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
dispatch({ type: AUTH_ACCOUNT_REMEMBER_REQUEST, accountUrl });
return KVStore.getItemOrError(`authAccount:${accountUrl}`).then(account => {
dispatch(importFetchedAccount(account));
dispatch({ type: AUTH_ACCOUNT_REMEMBER_SUCCESS, account, accountUrl });
if (account.id === getState().me) dispatch(fetchMeSuccess(account));
return account;
}).catch(error => {
dispatch({ type: AUTH_ACCOUNT_REMEMBER_FAIL, error, accountUrl, skipAlert: true });
});
};
export const loadCredentials = (token: string, accountUrl: string) =>
(dispatch: AppDispatch) => dispatch(rememberAuthAccount(accountUrl))
.finally(() => dispatch(verifyCredentials(token, accountUrl)));
export const logIn = (username: string, password: string) =>
(dispatch: AppDispatch) => dispatch(getAuthApp()).then(() => {
return dispatch(createUserToken(normalizeUsername(username), password));

View File

@ -1,11 +1,10 @@
import { selectAccount } from 'soapbox/selectors/index.ts';
import { setSentryAccount } from 'soapbox/sentry.ts';
import KVStore from 'soapbox/storage/kv-store.ts';
import { getAuthUserId, getAuthUserUrl } from 'soapbox/utils/auth.ts';
import api from '../api/index.ts';
import { loadCredentials } from './auth.ts';
import { verifyCredentials } from './auth.ts';
import { importFetchedAccount } from './importer/index.ts';
import type { RawAxiosRequestHeaders } from 'axios';
@ -51,22 +50,10 @@ const fetchMe = () =>
}
dispatch(fetchMeRequest());
return dispatch(loadCredentials(token, accountUrl!))
return dispatch(verifyCredentials(token, accountUrl!))
.catch(error => dispatch(fetchMeFail(error)));
};
/** Update the auth account in IndexedDB for Mastodon, etc. */
const persistAuthAccount = (account: APIEntity, params: Record<string, any>) => {
if (account && account.url) {
if (!account.pleroma) account.pleroma = {};
if (!account.pleroma.settings_store) {
account.pleroma.settings_store = params.pleroma_settings_store || {};
}
KVStore.setItem(`authAccount:${account.url}`, account).catch(console.error);
}
};
const patchMe = (params: Record<string, any>, isFormData = false) =>
(dispatch: AppDispatch, getState: () => RootState) => {
dispatch(patchMeRequest());
@ -78,7 +65,6 @@ const patchMe = (params: Record<string, any>, isFormData = false) =>
return api(getState)
.patch('/api/v1/accounts/update_credentials', params, { headers })
.then(response => {
persistAuthAccount(response.data, params);
dispatch(patchMeSuccess(response.data));
}).catch(error => {
dispatch(patchMeFail(error));

View File

@ -1,8 +1,6 @@
import { createSelector } from 'reselect';
import { getHost } from 'soapbox/actions/instance.ts';
import { normalizeSoapboxConfig } from 'soapbox/normalizers/index.ts';
import KVStore from 'soapbox/storage/kv-store.ts';
import { getFeatures } from 'soapbox/utils/features.ts';
import api from '../api/index.ts';
@ -31,17 +29,6 @@ const getSoapboxConfig = createSelector([
});
});
const rememberSoapboxConfig = (host: string | null) =>
(dispatch: AppDispatch) => {
dispatch({ type: SOAPBOX_CONFIG_REMEMBER_REQUEST, host });
return KVStore.getItemOrError(`soapbox_config:${host}`).then(soapboxConfig => {
dispatch({ type: SOAPBOX_CONFIG_REMEMBER_SUCCESS, host, soapboxConfig });
return soapboxConfig;
}).catch(error => {
dispatch({ type: SOAPBOX_CONFIG_REMEMBER_FAIL, host, error, skipAlert: true });
});
};
const fetchFrontendConfigurations = () =>
(dispatch: AppDispatch, getState: () => RootState) =>
api(getState)
@ -49,7 +36,7 @@ const fetchFrontendConfigurations = () =>
.then(({ data }) => data);
/** Conditionally fetches Soapbox config depending on backend features */
const fetchSoapboxConfig = (host: string | null) =>
const fetchSoapboxConfig = (host: string | null = null) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const features = getFeatures(getState().instance);
@ -67,16 +54,6 @@ const fetchSoapboxConfig = (host: string | null) =>
}
};
/** Tries to remember the config from browser storage before fetching it */
const loadSoapboxConfig = () =>
(dispatch: AppDispatch, getState: () => RootState) => {
const host = getHost(getState());
return dispatch(rememberSoapboxConfig(host)).then(() =>
dispatch(fetchSoapboxConfig(host)),
);
};
const fetchSoapboxJson = (host: string | null) =>
(dispatch: AppDispatch) =>
fetch('/instance/soapbox.json').then((response) => response.json()).then((data) => {
@ -115,10 +92,8 @@ export {
SOAPBOX_CONFIG_REMEMBER_SUCCESS,
SOAPBOX_CONFIG_REMEMBER_FAIL,
getSoapboxConfig,
rememberSoapboxConfig,
fetchFrontendConfigurations,
fetchSoapboxConfig,
loadSoapboxConfig,
fetchSoapboxJson,
importSoapboxConfig,
soapboxConfigFail,

View File

@ -8,7 +8,6 @@ import Text from 'soapbox/components/ui/text.tsx';
import Textarea from 'soapbox/components/ui/textarea.tsx';
import { useSoapboxConfig } from 'soapbox/hooks/useSoapboxConfig.ts';
import { captureSentryException } from 'soapbox/sentry.ts';
import KVStore from 'soapbox/storage/kv-store.ts';
import sourceCode from 'soapbox/utils/code.ts';
import { unregisterSW } from 'soapbox/utils/sw.ts';
@ -32,7 +31,6 @@ const SiteErrorBoundary: React.FC<ISiteErrorBoundary> = ({ children }) => {
const clearCookies: React.MouseEventHandler = (e) => {
localStorage.clear();
sessionStorage.clear();
KVStore.clear();
if ('serviceWorker' in navigator) {
e.preventDefault();

View File

@ -3,7 +3,7 @@ import { IntlProvider } from 'react-intl';
import { fetchMe } from 'soapbox/actions/me.ts';
import { loadSoapboxConfig } from 'soapbox/actions/soapbox.ts';
import { fetchSoapboxConfig } from 'soapbox/actions/soapbox.ts';
import LoadingScreen from 'soapbox/components/loading-screen.tsx';
import { useNostr } from 'soapbox/contexts/nostr-context.tsx';
import { useBunker } from 'soapbox/hooks/nostr/useBunker.ts';
@ -22,7 +22,7 @@ const loadInitial = () => {
// Await for authenticated fetch
await dispatch(fetchMe());
// Await for configuration
await dispatch(loadSoapboxConfig());
await dispatch(fetchSoapboxConfig());
};
};

View File

@ -1,7 +1,6 @@
import { List as ImmutableList, Map as ImmutableMap, fromJS } from 'immutable';
import { PLEROMA_PRELOAD_IMPORT } from 'soapbox/actions/preload.ts';
import KVStore from 'soapbox/storage/kv-store.ts';
import { ConfigDB } from 'soapbox/utils/config-db.ts';
import { ADMIN_CONFIG_UPDATE_SUCCESS } from '../actions/admin.ts';
@ -40,14 +39,7 @@ const preloadImport = (state: ImmutableMap<string, any>, action: Record<string,
}
};
const persistSoapboxConfig = (soapboxConfig: ImmutableMap<string, any>, host: string) => {
if (host) {
KVStore.setItem(`soapbox_config:${host}`, soapboxConfig.toJS()).catch(console.error);
}
};
const importSoapboxConfig = (state: ImmutableMap<string, any>, soapboxConfig: ImmutableMap<string, any>, host: string) => {
persistSoapboxConfig(soapboxConfig, host);
return soapboxConfig;
};

View File

@ -1,28 +0,0 @@
import localforage from 'localforage';
interface IKVStore extends LocalForage {
getItemOrError: (key: string) => Promise<any>;
}
// localForage
// https://localforage.github.io/localForage/#settings-api-config
export const KVStore = localforage.createInstance({
name: 'soapbox',
description: 'Soapbox offline data store',
driver: localforage.INDEXEDDB,
storeName: 'keyvaluepairs',
}) as IKVStore;
// localForage returns 'null' when a key isn't found.
// In the Redux action flow, we want it to fail harder.
KVStore.getItemOrError = (key: string) => {
return KVStore.getItem(key).then(value => {
if (value === null) {
throw new Error(`KVStore: null value for key ${key}`);
} else {
return value;
}
});
};
export default KVStore;

View File

@ -5297,11 +5297,6 @@ ignore@^6.0.2:
resolved "https://registry.yarnpkg.com/ignore/-/ignore-6.0.2.tgz#77cccb72a55796af1b6d2f9eb14fa326d24f4283"
integrity sha512-InwqeHHN2XpumIkMvpl/DCJVrAHgCsG5+cn1XlnLWGwtZBm8QJfSusItfrwx81CTp5agNZqpKU2J/ccC5nGT4A==
immediate@~3.0.5:
version "3.0.6"
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
integrity sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=
immer@^10.0.0, immer@^10.0.3:
version "10.0.3"
resolved "https://registry.yarnpkg.com/immer/-/immer-10.0.3.tgz#a8de42065e964aa3edf6afc282dfc7f7f34ae3c9"
@ -5889,13 +5884,6 @@ li@^1.3.0:
resolved "https://registry.yarnpkg.com/li/-/li-1.3.0.tgz#22c59bcaefaa9a8ef359cf759784e4bf106aea1b"
integrity sha512-z34TU6GlMram52Tss5mt1m//ifRIpKH5Dqm7yUVOdHI+BQCs9qGPHFaCUTIzsWX7edN30aa2WrPwR7IO10FHaw==
lie@3.1.1:
version "3.1.1"
resolved "https://registry.yarnpkg.com/lie/-/lie-3.1.1.tgz#9a436b2cc7746ca59de7a41fa469b3efb76bd87e"
integrity sha1-mkNrLMd0bKWd56QfpGmz77dr2H4=
dependencies:
immediate "~3.0.5"
lilconfig@^2.0.5, lilconfig@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/lilconfig/-/lilconfig-2.1.0.tgz#78e23ac89ebb7e1bfbf25b18043de756548e7f52"
@ -5949,13 +5937,6 @@ load-tsconfig@^0.2.3:
resolved "https://registry.yarnpkg.com/load-tsconfig/-/load-tsconfig-0.2.5.tgz#453b8cd8961bfb912dea77eb6c168fe8cca3d3a1"
integrity sha512-IXO6OCs9yg8tMKzfPZ1YmheJbZCiEsnBdcB03l0OcfK9prKnJb96siuHCr5Fl37/yo9DnKU+TLpxzTUspw9shg==
localforage@^1.10.0:
version "1.10.0"
resolved "https://registry.yarnpkg.com/localforage/-/localforage-1.10.0.tgz#5c465dc5f62b2807c3a84c0c6a1b1b3212781dd4"
integrity sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==
dependencies:
lie "3.1.1"
locate-path@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-6.0.0.tgz#55321eb309febbc59c4801d931a72452a681d286"