Skip to content

Commit

Permalink
Merge branch 'x' into fix/db-perf-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
originalix authored Dec 26, 2024
2 parents 518f3fc + 3cd6641 commit 57de8fa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/shared/src/storage/appStorageUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let _canSaveAsObject: boolean | null = null;
function canSaveAsObject(): boolean {
if (_canSaveAsObject === null) {
_canSaveAsObject = false;
if (platformEnv.isRuntimeBrowser) {
if (platformEnv.isRuntimeBrowser || platformEnv.isExtension) {
const isIndexedDB: boolean = (
appStorage as unknown as WebStorage
)?.isIndexedDB();
Expand Down
9 changes: 7 additions & 2 deletions packages/shared/src/storage/syncStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { isPlainObject } from 'lodash';

import appGlobals from '../appGlobals';
import platformEnv from '../platformEnv';
import { ensureRunOnBackground } from '../utils/assertUtils';
import dbPerfMonitor from '../utils/debug/dbPerfMonitor';
import resetUtils from '../utils/resetUtils';

Expand Down Expand Up @@ -30,14 +31,18 @@ export const buildAppStorageFactory = (
const setItem: IAppStorage['setItem'] = (key, value, callback) => {
resetUtils.checkNotInResetting();
dbPerfMonitor.logAppStorageCall('setItem', key);
ensureRunOnBackground();
return originalSetItem.call(storage, key, value, callback);
};
const getItem: IAppStorage['getItem'] = (key, callback) => {
dbPerfMonitor.logAppStorageCall('getItem', key);
ensureRunOnBackground();
return originalGetItem.call(storage, key, callback);
};
const removeItem: IAppStorage['removeItem'] = (key, callback) =>
originalRemoveItem.call(storage, key, callback);
const removeItem: IAppStorage['removeItem'] = (key, callback) => {
ensureRunOnBackground();
return originalRemoveItem.call(storage, key, callback);
};

storage.setItem = setItem;
storage.getItem = getItem;
Expand Down
8 changes: 4 additions & 4 deletions packages/shared/src/utils/assertUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
isUndefined,
} from 'lodash';

import appGlobals from '../appGlobals';
import errorUtils from '../errors/utils/errorUtils';
import platformEnv from '../platformEnv';
import appStorage from '../storage/appStorage';
import { EAppSyncStorageKeys } from '../storage/syncStorage';
import { EAppSyncStorageKeys } from '../storage/syncStorageKeys';

import { isPromiseObject } from './promiseUtils';
import timerUtils from './timerUtils';
Expand Down Expand Up @@ -108,15 +108,15 @@ export function toggleBgApiSerializableChecking(enabled: boolean) {
disabled: !enabled,
updateAt: Date.now(),
};
appStorage.syncStorage.setObject(
appGlobals.$appStorage?.syncStorage.setObject(
EAppSyncStorageKeys.onekey_disable_bg_api_serializable_checking,
data,
);
}
export function isBgApiSerializableCheckingDisabled() {
try {
const data =
appStorage.syncStorage.getObject<ISerializableCheckingDisabledConfig>(
appGlobals.$appStorage?.syncStorage.getObject<ISerializableCheckingDisabledConfig>(
EAppSyncStorageKeys.onekey_disable_bg_api_serializable_checking,
);
if (!data) {
Expand Down

0 comments on commit 57de8fa

Please sign in to comment.