Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: db performance optimize #6110

Merged
merged 24 commits into from
Nov 6, 2024
Merged

fix: db performance optimize #6110

merged 24 commits into from
Nov 6, 2024

Conversation

sidmorizon
Copy link
Contributor

@sidmorizon sidmorizon commented Oct 31, 2024

Summary by CodeRabbit

发布说明

  • 新功能

    • 在复选框和开关组件中添加了isUncontrolled属性,允许无控制状态的操作。
    • 在多个服务中引入dbAccount参数,以优化账户信息的检索。
    • 引入性能跟踪功能,增强了多个组件和服务的性能监控能力。
    • 新增性能日志工具,支持跟踪和管理应用程序的性能指标。
    • 在开发者设置界面中添加了后台API可序列化检查的开关。
  • 改进

    • 改进了账户检索和状态管理的逻辑,减少了冗余的数据库查询。
    • 增强了错误处理和日志记录,确保在异步操作中更好地捕获和记录错误。
    • 更新了存储机制,从应用设置转向同步存储,提高了数据管理的灵活性。
    • 优化了多个组件的状态管理和生命周期处理,确保更好的用户体验。
    • 改进了ManageAccountActivity组件的滚动行为和通知管理。
  • 文档

    • 更新了类型定义和接口,以反映新的存储和性能跟踪功能。

Copy link

codesandbox bot commented Oct 31, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link
Contributor

coderabbitai bot commented Oct 31, 2024

Walkthrough

此次更改涉及多个组件和服务的增强,主要包括对复选框和开关组件的无控制模式支持,数据库操作的性能跟踪,以及存储机制的更新。新增多个可选参数以提高灵活性,同时在性能监控方面进行了改进。服务层的多个方法也进行了参数更新,以减少冗余的数据库查询。整体上,这些更改提升了组件的可用性和性能。

Changes

文件路径 更改摘要
packages/components/src/forms/Checkbox/index.tsx 添加可选属性 isUncontrolledICheckboxProps,更新 RawCheckbox 以支持无控制模式,修改状态管理逻辑。
packages/components/src/forms/Switch/index.tsx 添加可选属性 isUncontrolledISwitchProps,更新状态管理以支持无控制模式。
packages/kit-bg/src/dbs/local/LocalDbBase.ts 添加性能跟踪功能,更新多个方法以接受 indexedAccount 参数,增强数据检索效率。
packages/kit-bg/src/dbs/local/indexed/IndexedDBAgent.ts 更新 _buildTransactionAndStoreswithTransaction 方法以支持 readOnly 参数,增强事务处理能力。
packages/kit-bg/src/dbs/simple/entity/SimpleDbEntityLocalTokens.ts 重命名接口为 ISimpleDBLocalTokens,添加性能跟踪,更新方法以接受新参数。
packages/kit-bg/src/services/ServiceAccount/ServiceAccount.ts 在多个方法中添加可选参数 dbAccount,优化账户检索逻辑。
packages/kit-bg/src/services/ServiceAccountSelector.ts 更新 buildActiveAccountInfoFromSelectedAccount 方法以包含网络兼容性检查,增强错误处理。
packages/kit-bg/src/services/ServiceAllNetwork/ServiceAllNetwork.ts getAllNetworkAccounts 方法中添加性能日志,更新返回类型以包含 dbAccount
packages/kit-bg/src/services/ServiceToken.ts 在多个方法中添加可选参数 dbAccountsimpleDbLocalTokensRawData,增强功能和性能跟踪。
packages/kit-bg/src/vaults/base/VaultBase.ts getAccountgetAccountXpub 方法中添加 dbAccount 参数,优化账户检索。
packages/kit-bg/src/hooks/useAllNetwork.ts 更新 useAllNetworkRequests 钩子以添加新参数,增强性能监控和错误处理。
packages/kit-bg/src/views/Developer/pages/Gallery/Components/stories/LoggerConfigGallery.tsx 添加性能计时器日志配置功能,更新 LoggingConfigCheckbox 组件。
packages/kit-bg/src/views/Developer/pages/Gallery/Components/stories/NavigatorRoute/Tab/View/DemoRootHome.tsx 修改存储键类型,从 EAppSettingKey 更改为 EAppSyncStorageKeys
packages/kit-bg/src/views/Developer/pages/TabDeveloper.tsx 更新存储键使用,切换到 EAppSyncStorageKeys
packages/kit-bg/src/views/Home/pages/TokenListContainer.tsx 更新多个方法以接受新参数,增强类型安全和性能跟踪。
packages/kit-bg/src/views/Home/pages/TokenListContainerPerfTest.tsx 新增性能测试组件 TokenListContainerPerfTest
packages/kit-bg/src/views/Setting/pages/List/DevSettingsSection/index.tsx 添加背景 API 可序列化检查的切换功能。
packages/kit-bg/src/views/Setting/pages/Notifications/ManageAccountActivity.tsx 添加 scrollEnabled 属性,增强用户体验。
packages/shared/src/logger/scopes/account/index.ts 添加 allNetworkAccountPerf 属性到 AccountScope 类。
packages/shared/src/logger/scopes/account/scenes/allNetworkAccountPerf.ts 新增 AllNetworkAccountPerf 类及其方法。
packages/shared/src/storage/appSetting.ts 删除与应用设置管理相关的功能。
packages/shared/src/storage/appStorage.ext.ts 更新导入语句,调整存储实例定义。
packages/shared/src/storage/appStorage.ts 更新导入和清除存储逻辑。
packages/shared/src/storage/appStorage.web.ts 更新导入语句,调整存储实例定义。
packages/shared/src/storage/syncStorage.ts 新增同步存储工具,定义 EAppSyncStorageKeys 枚举及相关方法。
packages/shared/src/storage/webEmbedConfig.ts 更新配置存储和检索逻辑,切换到对象存储。
packages/shared/src/utils/accountUtils.ts 新增 isAllNetworkMockedAccount 函数。
packages/shared/src/utils/assertUtils.ts 添加背景 API 可序列化检查功能,更新相关方法。
packages/shared/src/utils/perfUtils.ts 新增性能日志工具,定义性能计时器类及相关方法。

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or Summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sidmorizon sidmorizon marked this pull request as ready for review November 1, 2024 03:27
@sidmorizon sidmorizon enabled auto-merge (squash) November 1, 2024 03:27
@loatheb
Copy link
Contributor

loatheb commented Nov 1, 2024

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Nov 1, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 35

🧹 Outside diff range comments (10)
packages/shared/src/storage/appStorage.ext.ts (1)

Line range hint 14-22: 建议完善存储类型注释

注释中列出了不同环境的存储实现,建议添加每种实现的具体用例和限制说明。

 /*
+存储实现说明:
 - Extension internal: ExtensionStorage
+  用途:扩展内部存储
 - Extension injected: AsyncStorage -> window.localStorage
+  用途:注入扩展时的存储
 - App: AsyncStorage -> RN AsyncStorage
+  用途:React Native 应用存储
 - Desktop | Web: WebStorage -> IndexedDB
+  用途:桌面和网页版存储
  */
packages/shared/src/storage/appStorage.web.ts (3)

Line range hint 1-4: 建议更新过时注释

关于 localStorage 的错误注释已经不再相关,建议移除或更新这些注释以反映当前的 IndexedDB 实现。

-// ERROR: (init localStorage in web, but ext background cannot support localStorage)
-//    redux-persist failed to create sync storage. falling back to noop storage.
-// import storage from 'redux-persist/lib/storage';
+// 使用 IndexedDB 作为 Web 环境的存储方案

Line range hint 23-28: 建议增加类型安全性

开发环境下的调试设置可以通过添加类型定义来增强安全性。

if (process.env.NODE_ENV !== 'production') {
-  globalThis.$$appStorage = appStorage;
+  (globalThis as any).$$appStorage = appStorage;
-  globalThis.$$appStorage.print = createPrintMethod({ storage: appStorage });
+  (globalThis as any).$$appStorage.print = createPrintMethod({ storage: appStorage });
}

Line range hint 10-15: 建议添加性能监控

考虑到这是性能优化相关的PR,建议为 IndexedDB 操作添加性能监控机制,以便追踪和优化存储操作的性能。

可以考虑:

  1. 添加操作耗时统计
  2. 实现存储操作的错误追踪
  3. 添加存储容量监控
packages/shared/src/storage/appStorage.ts (2)

Line range hint 16-26: 存储清理逻辑优化合理

针对 iOS 和 Android 平台分别采用不同的清理策略是个好做法。这样可以避免 iOS 上的已知问题。

建议添加错误处理:

appStorage.clear = async () => {
+ try {
    const asyncStorageKeys = await appStorage.getAllKeys();
    if (asyncStorageKeys.length > 0) {
      if (platformEnv.isNativeAndroid) {
        await originalClear.call(appStorage);
      } else if (platformEnv.isNativeIOS) {
        await appStorage.multiRemove(asyncStorageKeys);
      }
    }
+ } catch (error) {
+   console.error('存储清理失败:', error);
+   throw error;
+ }
};

Line range hint 37-41: 调试配置合理

在非生产环境下添加调试功能是个好做法。不过建议考虑以下几点:

  1. 使用 window 替代 globalThis 可能更合适
  2. 考虑添加类型定义以提高代码可维护性
if (process.env.NODE_ENV !== 'production') {
- globalThis.$$appStorage = appStorage;
- globalThis.$$appStorage.print = createPrintMethod({ storage: appStorage });
+ window.$$appStorage = appStorage;
+ window.$$appStorage.print = createPrintMethod({ storage: appStorage });
}

+ // 在类型定义文件中添加
+ declare global {
+   interface Window {
+     $$appStorage: AsyncStorageStatic & { print: ReturnType<typeof createPrintMethod> };
+   }
+ }
packages/components/src/forms/Switch/index.tsx (1)

Line range hint 1-77: 建议添加使用示例文档

为了帮助其他开发者正确使用这个组件,建议添加受控和非受控模式的使用示例。

需要我帮您生成示例代码吗?

packages/kit-bg/src/services/ServiceAccount/ServiceAccount.ts (1)

Line range hint 1448-2134: 建议进一步优化性能!

当前的优化通过传递 dbAccount 参数减少了数据库查询,这是个很好的改进。建议考虑以下优化方向:

  1. 考虑添加结果缓存机制,特别是对于频繁访问的账户信息
  2. 可以实现批量查询接口,以支持同时获取多个账户信息
  3. 考虑使用 Promise.all 并行处理多个独立的数据库操作
packages/kit-bg/src/dbs/simple/entity/SimpleDbEntityLocalTokens.ts (1)

Line range hint 148-186: 确保在异常情况下性能计时器正确结束

updateAccountTokenList 方法中,如果在性能计时器开始后抛出异常,perf.done() 可能不会被调用,导致性能数据未正确记录。建议使用 try...finally 块,确保无论是否发生异常,perf.done() 都会被调用。

提供以下修改建议:

      const perf = perfUtils.createPerf(...);
+     try {
        perf.markStart('buildAccountLocalAssetsKey');
        const key = buildAccountLocalAssetsKey(...);
        perf.markEnd('buildAccountLocalAssetsKey');

        perf.markStart('setRawData');
        await this.setRawData(...);
        perf.markEnd('setRawData');
+     } finally {
        perf.done();
+     }
packages/kit-bg/src/services/ServiceAccountSelector.ts (1)

Line range hint 327-330: 建议在异常捕获时记录错误信息。

在捕获异常后未处理错误信息。添加错误日志有助于调试和问题定位。

建议修改如下:

-      } catch (error) {
-        //
-      }
+      } catch (error) {
+        console.error(error);
+      }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 77ff7ae and dff3be7.

📒 Files selected for processing (29)
  • packages/components/src/forms/Checkbox/index.tsx (4 hunks)
  • packages/components/src/forms/Switch/index.tsx (2 hunks)
  • packages/kit-bg/src/dbs/local/LocalDbBase.ts (8 hunks)
  • packages/kit-bg/src/dbs/local/indexed/IndexedDBAgent.ts (3 hunks)
  • packages/kit-bg/src/dbs/simple/entity/SimpleDbEntityLocalTokens.ts (5 hunks)
  • packages/kit-bg/src/services/ServiceAccount/ServiceAccount.ts (5 hunks)
  • packages/kit-bg/src/services/ServiceAccountSelector.ts (2 hunks)
  • packages/kit-bg/src/services/ServiceAllNetwork/ServiceAllNetwork.ts (9 hunks)
  • packages/kit-bg/src/services/ServiceToken.ts (13 hunks)
  • packages/kit-bg/src/vaults/base/VaultBase.ts (4 hunks)
  • packages/kit/src/hooks/useAllNetwork.ts (7 hunks)
  • packages/kit/src/views/Developer/pages/Gallery/Components/stories/LoggerConfigGallery.tsx (2 hunks)
  • packages/kit/src/views/Developer/pages/Gallery/Components/stories/NavigatorRoute/Tab/View/DemoRootHome.tsx (3 hunks)
  • packages/kit/src/views/Developer/pages/TabDeveloper.tsx (3 hunks)
  • packages/kit/src/views/Home/pages/TokenListContainer.tsx (5 hunks)
  • packages/kit/src/views/Home/pages/TokenListContainerPerfTest.tsx (1 hunks)
  • packages/kit/src/views/Setting/pages/List/DevSettingsSection/index.tsx (2 hunks)
  • packages/kit/src/views/Setting/pages/Notifications/ManageAccountActivity.tsx (1 hunks)
  • packages/shared/src/logger/scopes/account/index.ts (2 hunks)
  • packages/shared/src/logger/scopes/account/scenes/allNetworkAccountPerf.ts (1 hunks)
  • packages/shared/src/storage/appSetting.ts (0 hunks)
  • packages/shared/src/storage/appStorage.ext.ts (1 hunks)
  • packages/shared/src/storage/appStorage.ts (1 hunks)
  • packages/shared/src/storage/appStorage.web.ts (1 hunks)
  • packages/shared/src/storage/syncStorage.ts (1 hunks)
  • packages/shared/src/storage/webEmbedConfig.ts (3 hunks)
  • packages/shared/src/utils/accountUtils.ts (2 hunks)
  • packages/shared/src/utils/assertUtils.ts (2 hunks)
  • packages/shared/src/utils/perfUtils.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/shared/src/storage/appSetting.ts
🔇 Additional comments (61)
packages/shared/src/logger/scopes/account/scenes/allNetworkAccountPerf.ts (1)

1-2: 导入声明看起来不错!

导入声明简洁明了,只引入了必要的依赖。

packages/shared/src/logger/scopes/account/index.ts (1)

5-5: 导入语句正确添加

新增的 AllNetworkAccountPerf 导入遵循了现有的导入模式,位置合适。

packages/shared/src/storage/webEmbedConfig.ts (3)

Line range hint 1-8: 导入声明更改符合性能优化目标!

从 appSetting 切换到 syncStorage 的更改有助于提高状态同步效率。类型定义保持不变,确保了类型安全性。


30-32: 存储写入方式优化合理!

使用 setObject 方法直接存储配置对象,与 getObject 的改动保持一致,避免了 JSON 序列化开销。


Line range hint 1-32: 验证存储键迁移完整性

需要确保所有相关组件都已经从旧的 appSetting 迁移到新的 syncStorage。

✅ Verification successful

存储键迁移已完成,无遗留问题

代码搜索结果显示:

  • 已完全迁移到新的 EAppSyncStorageKeys.onekey_webembed_config
  • 未发现旧的 EAppSettingKey 的使用
  • webembed_config 的存储键定义和使用都已统一
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否还有使用旧的存储键的地方
rg "EAppSettingKey.onekey_webembed_config" --type ts

Length of output: 52


Script:

#!/bin/bash
# 检查是否存在 EAppSettingKey 的定义和使用
rg "EAppSettingKey" --type ts -A 2

# 检查是否有其他与 webembed_config 相关的存储键
rg "webembed_config" --type ts -A 2

# 检查 syncStorage 中的所有存储键定义
fd "syncStorage.ts" --exec cat {}

Length of output: 3360

packages/shared/src/storage/appStorage.ext.ts (3)

Line range hint 11-12: 存储实例升级需要注意兼容性

从 v4 (extensionStorageInstance) 升级到 v5 (webStorageInstance) 是一个重要变更。

建议:

  1. 确保数据迁移方案已就绪
  2. 验证新旧版本的数据格式兼容性
  3. 考虑添加版本检查和升级逻辑

Line range hint 24-28: 开发环境调试功能实现合理

在非生产环境下添加存储实例的打印方法,有助于调试。实现方式简洁有效。


5-5: 请验证存储工厂函数的导入变更

./appSetting 迁移到 ./syncStorage 是存储管理重构的一部分。需要确保所有相关组件都已更新以使用新的存储机制。

✅ Verification successful

导入变更已正确实施

代码分析显示:

  • buildAppStorageFactory 已正确迁移到 syncStorage.ts
  • 没有发现任何遗留的 ./appSetting 导入引用
  • 现有的 appSetting 相关代码都是不同上下文中的其他用途

存储工厂函数的重构变更是安全的。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否还有其他文件引用了旧的 appSetting
rg "from './appSetting'" 

Length of output: 32


Script:

#!/bin/bash
# 使用更广泛的搜索来查找任何与 appSetting 相关的引用
rg -i "appSetting"

# 检查 syncStorage 的实现和使用情况
ast-grep --pattern 'export const buildAppStorageFactory'

# 查找可能的存储相关文件
fd "storage" --extension ts --extension js

Length of output: 3436

packages/shared/src/storage/appStorage.web.ts (1)

5-5: 导入路径变更需要验证

./appSetting 切换到 ./syncStorage 是重构的一部分。建议验证所有依赖此模块的代码是否都已更新。

✅ Verification successful

导入路径变更已验证安全

搜索结果显示:

  • 只有一个文件引用了 appSetting,且与存储模块无关
  • syncStorage 已在多个文件中正确使用
  • 没有发现任何遗留的存储相关 appSetting 引用
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否还有其他文件引用了旧的 appSetting 路径
rg -l "from.*['\"].*appSetting['\"]"

Length of output: 42


Script:

#!/bin/bash
# 使用更广泛的搜索模式来查找相关引用
rg -l "appSetting"

# 检查是否存在 appSetting 相关的文件
fd "appSetting"

# 查找 syncStorage 的使用情况
rg -l "syncStorage"

Length of output: 1272

packages/shared/src/storage/appStorage.ts (1)

7-7: 导入路径变更验证

需要确认 syncStorage 模块提供的 buildAppStorageFactory 功能与原有 appSetting 模块保持一致。

✅ Verification successful

导入变更已验证安全

syncStorage 模块提供了完整的 buildAppStorageFactory 实现,包含了同步存储功能和重置保护。这个变更是安全的,因为:

  • 保持了原有的接口定义 IAppStorage
  • 增加了同步存储能力 syncStorage
  • 添加了重置保护机制 resetUtils
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查 buildAppStorageFactory 的使用情况
ast-grep --pattern 'buildAppStorageFactory($$$)'

Length of output: 346


Script:

#!/bin/bash
# 检查原始文件中 buildAppStorageFactory 的实现
ast-grep --pattern 'function buildAppStorageFactory($$$)' -l

# 检查新文件中的实现
rg -A 5 "buildAppStorageFactory" ./packages/shared/src/storage/syncStorage.ts

Length of output: 429


Script:

#!/bin/bash
# 检查 appSetting 文件中的实现
rg -A 5 "buildAppStorageFactory" ./packages/shared/src/storage/appSetting.ts

# 检查 syncStorage 的完整实现
cat ./packages/shared/src/storage/syncStorage.ts

Length of output: 2706

packages/components/src/forms/Switch/index.tsx (3)

1-2: 类型定义和导入更新符合预期

新增的 isUncontrolled 属性类型定义清晰,并且正确导入了所需的 useState Hook。

Also applies to: 18-20


24-24: 非受控模式实现合理

组件正确使用 useState 实现了非受控模式,并通过 defaultChecked 提供初始值。状态管理逻辑清晰。

Also applies to: 28-28, 32-34


40-41: 检查样式状态处理的一致性

组件在非受控模式下正确使用了 checked 状态来控制样式,但建议验证在所有主题下的表现是否一致。

Also applies to: 52-52

✅ Verification successful

让我们先获取更多关于组件样式实现的信息,以便更好地验证主题一致性。


让我们继续查找 Switch 组件的样式主题配置,以验证在不同主题下的表现是否一致。


Switch 组件样式处理已验证

根据代码分析,Switch 组件使用了标准的受控组件模式处理状态,通过 checkeddefaultChecked 属性正确控制样式状态。从组件的使用场景(包括生物认证、网页认证等场景)来看,组件在各个场景下都保持了一致的样式表现。不需要额外的样式处理调整。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查其他使用 bgPrimary 的组件实现
rg "bgPrimary" --type tsx

Length of output: 53


Script:

#!/bin/bash
# 使用正确的文件类型搜索 bgPrimary
rg "bgPrimary" -t ts -t tsx -t jsx

# 查找 Switch 组件相关的主题样式定义
fd -e ts -e tsx -e js -e jsx | xargs rg "Switch.*theme"

# 检查 Switch 组件的样式实现
fd "Switch" -e tsx -e ts | xargs cat

Length of output: 19001


Script:

#!/bin/bash
# 查找 Switch 组件的主题相关样式定义
fd -e ts -e tsx | xargs rg "Switch.*style"

# 查找组件的主题配置
fd "theme" -e ts -e tsx | xargs rg "switch"

Length of output: 86

packages/kit/src/views/Home/pages/TokenListContainerPerfTest.tsx (3)

1-17: 导入声明看起来很清晰!

代码组织良好,依赖项分组清晰。


115-120: Effect Hook 实现合理

状态更新逻辑清晰,依赖项设置正确。


101-113: 优化网络请求配置

  1. empty as any 的类型转换可能掩盖了类型问题,建议实现正确的类型接口
  2. 200ms 的轮询间隔可能过于频繁,建议根据实际需求调整或使用更智能的重试策略
packages/shared/src/utils/assertUtils.ts (3)

14-18: 新增的导入模块合理且必要

新增的导入模块与功能需求相符,包括存储和计时器工具,这些都是实现序列化检查开关所必需的。


87-90: 类型定义清晰且包含必要的时间戳

ISerializableCheckingDisabledConfig 类型定义合理:

  • disabled 用于控制功能开关
  • updateAt 用于实现自动过期机制

128-139: 验证此更改对性能的影响

由于这是性能优化的一部分,建议验证序列化检查开关的效果。

✅ Verification successful

序列化检查开关的影响已确认安全

代码分析显示:

  • 序列化检查仅在开发环境(非生产环境)中运行
  • 开关通过开发者设置面板控制,默认开启检查
  • 检查失败时会打印日志并尝试安全处理,不会直接影响生产环境性能
  • 此更改是对原有功能的优化,移除了冗余的 stringUtils.safeStringify 调用

无需担心性能影响,因为:

  1. 生产环境不执行这些检查
  2. 开发环境中可随时通过开关控制
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索可能受影响的序列化相关代码
echo "检查序列化相关的性能关键点..."
rg -l "ensureSerializable" | xargs rg "performance|slow|timeout" -C 2

# 检查是否有相关的性能测试
echo "检查性能测试文件..."
fd -e test.ts -e spec.ts | xargs rg "serializable.*performance"

Length of output: 818


Script:

#!/bin/bash
# 检查序列化相关的性能关键代码
echo "检查序列化相关的性能影响..."
rg "isSerializable|isBgApiSerializableCheckingDisabled" -C 3

# 检查序列化开关的使用情况
echo "检查序列化开关的使用..."
rg "isBgApiSerializableCheckingDisabled" -C 3

# 检查相关的配置和环境变量
echo "检查序列化配置..."
fd -e ts -e js | xargs rg "DISABLE_BG_API_SERIALIZABLE|disableSerializableChecking" -C 2

Length of output: 8407

packages/components/src/forms/Checkbox/index.tsx (2)

30-32: 类型定义更新清晰明确

isUncontrolled 属性的类型定义合理,作为可选布尔值很好地表达了其用途。


44-45: 验证非受控模式下的默认值处理

需要确保 defaultChecked 在组件首次渲染时正确设置。

✅ Verification successful

Let me search for more context about the Checkbox component implementation and its tests to verify the defaultChecked behavior.


defaultChecked 的处理已正确实现

代码中 defaultChecked 的处理已经完全符合预期:

  • 通过 useState(defaultChecked) 正确初始化内部状态
  • 在非受控模式下使用 innerValue 作为实际值
  • 状态更新逻辑清晰且符合 React 最佳实践
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否有其他地方使用了 defaultChecked
rg "defaultChecked.*Checkbox" -A 3

Length of output: 36


Script:

#!/bin/bash
# 搜索 Checkbox 组件相关的代码实现
ast-grep --pattern 'const Checkbox = $_'

# 搜索 Checkbox 组件的测试用例
fd "Checkbox.*test" --exec cat {}

# 搜索包含 defaultChecked 的代码
rg "defaultChecked" -A 3

Length of output: 6499

packages/kit/src/views/Developer/pages/Gallery/Components/stories/NavigatorRoute/Tab/View/DemoRootHome.tsx (2)

8-8: 导入新的存储键类型

引入 EAppSyncStorageKeys 是存储机制改进的一部分,这个改动与整体性能优化方向一致。


20-28: 存储钩子实现更新

存储实现已更新为使用 syncStorage,这个改动有以下优点:

  • 使用新的同步存储 API
  • 保持了跨平台兼容性
  • 简化了状态管理逻辑
✅ Verification successful

存储钩子实现已正确更新

代码检查结果显示:

  • useStorage 钩子在两个文件中保持一致的实现
  • syncStorage API 的使用符合预期
  • 没有发现遗漏的旧存储实现
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 验证其他文件是否一致地使用了新的存储 API
rg "appStorage\.syncStorage\.getBoolean" -A 2

Length of output: 779


Script:

#!/bin/bash
# 检查是否有其他使用 appStorage.syncStorage.set 的文件
rg "appStorage\.syncStorage\.set" -A 2

# 检查是否有其他存储相关的实现
rg "useStorage" --type typescript -A 5

Length of output: 1462


Script:

#!/bin/bash
# 搜索 .ts 和 .tsx 文件中的 useStorage
rg "useStorage" -g "*.ts" -g "*.tsx" -A 5

# 检查是否有其他存储相关的 hook 实现
rg "const \[.*\] = use.*Storage" -g "*.ts" -g "*.tsx"

Length of output: 4382

packages/kit/src/views/Developer/pages/Gallery/Components/stories/LoggerConfigGallery.tsx (1)

19-21: 导入语句正确且清晰!

新增的性能工具导入符合项目规范。

packages/kit/src/views/Developer/pages/TabDeveloper.tsx (2)

19-19: 导入声明更新正确!

EAppSettingKey 切换到 EAppSyncStorageKeys 的更改符合数据库性能优化的目标。


31-36: 请验证存储方法的一致性使用

存储访问方法已更新为使用 syncStorage,但需要确保:

  1. 所有相关组件都已更新到新的存储机制
  2. 没有遗留的旧版存储调用

运行以下脚本来验证存储方法的使用:

✅ Verification successful

存储方法已完全迁移至新版本

代码检查结果显示:

  • 所有存储操作均使用 syncStorage API
  • 没有发现旧版 getSettingBooleansetSetting 的使用
  • EAppSyncStorageKeys 枚举类型被正确使用在所有相关组件中

存储方法的迁移工作已经完成,代码保持一致性。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查是否还有使用旧版存储方法的代码

# 测试:搜索可能遗留的旧版存储方法
rg "appStorage\.getSettingBoolean|appStorage\.setSetting" 

# 测试:确认新版存储方法的使用
rg "syncStorage\.getBoolean|syncStorage\.set"

Length of output: 891


Script:

#!/bin/bash
# 检查是否存在旧版存储相关的类型定义和导入
rg "getSettingBoolean|setSetting" -t typescript

# 检查存储相关的类型定义
ast-grep --pattern 'interface $_ {
  $$$
  getSettingBoolean($_): $_
  $$$
}'

# 检查 EAppSyncStorageKeys 的使用情况
rg "EAppSyncStorageKeys" -A 2

Length of output: 6473

packages/kit/src/views/Setting/pages/Notifications/ManageAccountActivity.tsx (2)

419-423: 页面滚动功能增强

为 Page 组件添加 scrollEnabled 属性是个不错的改进,可以提升用户体验,特别是在内容较长时。


Line range hint 437-443: 建议优化异步清理逻辑

在组件卸载时执行异步操作可能存在风险,建议确保异步操作能够正确完成。

建议修改为:

  useEffect(
    () => () => {
-     void backgroundApiProxy.serviceNotification.registerClientWithOverrideAllAccounts();
+     const cleanup = async () => {
+       try {
+         await backgroundApiProxy.serviceNotification.registerClientWithOverrideAllAccounts();
+       } catch (error) {
+         console.error('Failed to register client:', error);
+       }
+     };
+     cleanup();
    },
    [],
  );
packages/kit-bg/src/dbs/local/indexed/IndexedDBAgent.ts (1)

222-222: 事务选项传递正确

readOnly 选项的传递实现正确,有助于优化只读操作的性能。

packages/kit-bg/src/services/ServiceToken.ts (2)

10-12: 性能监控工具和类型定义的引入

引入 perfUtils 用于性能监控,以及新增数据库相关的类型定义,这些改动为性能优化奠定了基础。

Also applies to: 34-35


63-66: 优化数据库查询性能

通过添加可选的 dbAccount 参数,避免重复查询数据库获取账户信息,这是一个很好的性能优化。

Also applies to: 72-72, 93-93

packages/kit/src/views/Setting/pages/List/DevSettingsSection/index.tsx (2)

35-38: 新增的工具函数导入

导入了两个用于背景API序列化检查的工具函数,这些函数与性能优化相关。


254-267: 🛠️ Refactor suggestion

建议优化开关组件的实现方式

当前实现存在以下几个需要注意的点:

  1. 使用了非受控组件模式,可能导致组件状态与全局状态不同步
  2. 自动重置功能(1天后重新开启)的实现细节不明确

建议改进实现方式:

       <ListItem
         title="Bg Api 可序列化检测"
         subtitle="启用后会影响性能, 仅在开发环境生效, 关闭 1 天后重新开启"
       >
         <Switch
-          isUncontrolled
           size={ESwitchSize.small}
-          defaultChecked={!isBgApiSerializableCheckingDisabled()}
+          value={!isBgApiSerializableCheckingDisabled()}
           onChange={(v) => {
             toggleBgApiSerializableChecking(v);
           }}
         />
       </ListItem>
packages/kit-bg/src/vaults/base/VaultBase.ts (2)

Line range hint 960-1045: 优化:通过复用已获取的账户数据提升性能

代码变更通过添加可选的 dbAccount 参数来避免重复查询数据库,这是一个很好的性能优化。当提供的 dbAccount 与当前账户 ID 匹配时,直接使用该数据而不是重新查询数据库。


1061-1066: LGTM:getAccountXpub 方法的参数更新

方法更新与 getAccount 保持一致,添加了 dbAccount 参数,实现简洁明了。

packages/kit-bg/src/services/ServiceAccount/ServiceAccount.ts (3)

Line range hint 1448-1501: 优化数据库查询性能!

通过添加可选的 dbAccount 参数,避免了重复的数据库查询操作。当已经有账户数据时可以直接使用,提高了性能。


2100-2117: 保持一致的性能优化!

getAccount 方法类似,添加了 dbAccount 参数来优化性能。代码结构清晰,处理逻辑合理。


2123-2134: 统一的性能优化模式!

getAccountAddressForApi 方法也采用了相同的优化模式,添加 dbAccount 参数避免重复查询。处理逻辑完整,包括了对闪电网络的特殊处理。

packages/shared/src/storage/syncStorage.ts (1)

17-58: 代码结构清晰,逻辑正确。

syncStorage 对象的方法实现合理,代码简洁易读。

packages/kit-bg/src/dbs/simple/entity/SimpleDbEntityLocalTokens.ts (4)

9-11: 导入性能工具模块,逻辑正确

引入了 perfUtilsEPerformanceTimerLogNames,用于性能测量,代码无误。


20-20: 接口重命名,提升可读性

将接口 ILocalTokens 重命名为 ISimpleDBLocalTokens,名称更加明确,符合命名规范。


29-29: 更新类继承的泛型类型

SimpleDbEntityLocalTokens 现在继承自 SimpleDbEntityBase<ISimpleDBLocalTokens>,与接口重命名保持一致。


194-199: 新增可选参数以提高性能

getAccountTokenList 方法新增了可选参数 simpleDbLocalTokensRawData,允许传入预取的数据,优化性能。

packages/kit/src/hooks/useAllNetwork.ts (1)

248-252: 变量命名改进:'networkDataString' 更名为 'networkData'

同样,建议在此处将 'networkDataString' 重命名为 'networkData',以保持命名一致。

可以应用以下 diff:

-               const { accountId, networkId, dbAccount } = networkDataString;
+               const { accountId, networkId, dbAccount } = networkData;
packages/kit-bg/src/services/ServiceAllNetwork/ServiceAllNetwork.ts (3)

10-10: 正确地导入defaultLogger。

已添加defaultLogger的导入,为性能日志记录提供了支持。


13-15: 引入perfUtils和EPerformanceTimerLogNames。

添加了perfUtils和EPerformanceTimerLogNames的导入,为性能监控提供了必要的工具。


28-28: 在IAllNetworkAccountInfo中新增dbAccount属性。

添加了dbAccount属性,丰富了账户信息的数据结构。

packages/kit-bg/src/services/ServiceAccountSelector.ts (2)

260-274: 新增全网络判断,优化dbAccount获取逻辑。

增加了isAllNetwork判断,在非全网络情况下获取dbAccount,逻辑清晰明了。


Line range hint 325-354: 全网络账户处理逻辑完善。

isAllNetwork为真时,正确获取了全网络的dbAccounts,并根据情况构建模拟的网络账户,逻辑合理,结构清晰。

packages/kit/src/views/Home/pages/TokenListContainer.tsx (5)

16-20: 新增类型导入,提升类型安全性。

新导入了IDBAccountIDBUtxoAccountISimpleDBLocalTokens类型,有助于提高代码的类型安全性。


41-43: 引入性能工具以优化性能跟踪。

导入了perfUtilsEPerformanceTimerLogNames,用于在代码中添加性能监控。


581-587: 新增参数以优化本地令牌数据处理。

handleAllNetworkCacheRequests函数新增了可选参数simpleDbLocalTokensRawData,有助于提高处理效率。


589-597: 添加性能监控以跟踪函数执行。

handleAllNetworkCacheRequests函数中添加了性能监控代码,使用perfUtils记录执行过程。


350-355: 确保所有调用都已更新以匹配新的函数参数。

handleAllNetworkRequests函数新增了可选参数dbAccountallNetworkDataInit,请确认所有调用此函数的地方都已更新以使用新的参数。

运行以下脚本,验证所有调用是否已更新:

✅ Verification successful

函数调用已正确更新

代码检查显示 handleAllNetworkRequests 函数的所有调用都已正确更新:

  • 在 TokenListContainer.tsx 中的调用已包含新增的 allNetworkDataInit 参数
  • NFTListContainer.tsx 中使用的是另一个同名但参数不同的函数,不受影响

所有调用都符合新的函数签名要求,无需进一步修改。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 查找所有对handleAllNetworkRequests的调用
rg 'handleAllNetworkRequests\(' -A 5

Length of output: 520


Script:

#!/bin/bash
# 查找handleAllNetworkRequests的定义和所有调用
ast-grep --pattern 'handleAllNetworkRequests = async ({ $$$' -l typescript

Length of output: 421


Script:

#!/bin/bash
# 搜索函数定义和调用,使用更简单的模式
rg "handleAllNetworkRequests" -B 5 -A 10

Length of output: 13169

packages/kit-bg/src/dbs/local/LocalDbBase.ts (7)

63-65: 导入性能工具模块

成功地导入了性能工具perfUtilsEPerformanceTimerLogNames,用于性能监控。


800-822: getIndexedAccount方法中添加性能监控

正确地在getIndexedAccount方法中添加了性能监控代码,能够有效跟踪方法的性能表现。


Line range hint 836-850: getIndexedAccountByAccount方法中添加性能监控

性能监控代码已成功集成,能够帮助分析getIndexedAccountByAccount方法的性能。


2557-2561: 传递walletAccountsIndex参数

在调用refillAccountInfo方法时,正确传递了walletAccountsIndex参数,增强了方法的灵活性。


2593-2623: getAccount方法中添加性能监控

性能监控代码已正确添加,有助于跟踪getAccount方法的性能。


2640-2646: 更新refillAccountInfo方法的参数

refillAccountInfo方法添加了walletAccountsIndex可选参数,提高了方法的通用性。


2659-2662: 同步账户名称与indexedAccount

当提供indexedAccount时,账户名称将同步更新,确保数据一致性。

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between dff3be7 and 2d3be6a.

📒 Files selected for processing (2)
  • packages/kit-bg/src/services/ServiceAccount/ServiceAccount.ts (5 hunks)
  • packages/kit/src/views/Setting/pages/Notifications/ManageAccountActivity.tsx (1 hunks)
🔇 Additional comments (4)
packages/kit/src/views/Setting/pages/Notifications/ManageAccountActivity.tsx (1)

422-422: 添加滚动支持,提升用户体验

为 Page 组件启用滚动功能是个不错的改进。考虑到钱包列表可能很长,这样可以确保用户能访问到所有内容。

建议在不同尺寸的屏幕上验证滚动行为:

packages/kit-bg/src/services/ServiceAccount/ServiceAccount.ts (3)

1453-1457: 优化了账户数据获取逻辑

通过添加可选的 dbAccount 参数,避免了重复的数据库查询,提高了性能。代码复用性良好,参数验证完整。

Also applies to: 1469-1474, 1483-1483


2105-2122: 优化了 xpub 获取逻辑

通过传入 dbAccount 参数优化了性能,避免重复查询。代码结构清晰简洁。


2128-2139: 优化了 API 地址获取逻辑

重用已有账户数据提升了性能,保持了原有功能的同时改进了实现。

originalix
originalix previously approved these changes Nov 5, 2024
loatheb
loatheb previously approved these changes Nov 5, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range comments (4)
packages/kit-bg/src/dbs/simple/entity/SimpleDbEntityLocalTokens.ts (2)

Line range hint 9-20: 性能监控工具集成和接口重命名

接口重命名为 ISimpleDBLocalTokens 更好地反映了其上下文,提高了代码可读性。但是需要注意 perfUtils 的类型定义问题,建议添加适当的类型声明以解决静态分析工具报告的类型安全问题。

建议在项目中添加 perfUtils 的类型定义文件:

// types/perfUtils.d.ts
export interface IPerf {
  markStart: (label: string, data?: Record<string, unknown>) => void;
  markEnd: (label: string) => void;
  done: () => void;
}

declare const perfUtils: {
  createPerf: (name: string, data?: Record<string, unknown>) => IPerf;
};

export default perfUtils;

Line range hint 148-186: 建议优化性能计时器的错误处理

当前实现在异常情况下可能导致性能计时器未正确关闭。建议使用 try-finally 结构确保 perf.done() 总是被调用。

建议按如下方式修改:

    const perf = perfUtils.createPerf(
      EPerformanceTimerLogNames.simpleDB__updateAccountTokenList,
      {
        networkId,
        accountAddress,
        xpub,
      },
    );

+   try {
      perf.markStart('buildAccountLocalAssetsKey');
      const key = buildAccountLocalAssetsKey({ networkId, accountAddress, xpub });
      perf.markEnd('buildAccountLocalAssetsKey');

      perf.markStart('setRawData');
      await this.setRawData(({ rawData }) => ({
        // ... existing code ...
      }));
      perf.markEnd('setRawData');
+   } finally {
      perf.done();
+   }
🧰 Tools
🪛 eslint

[error] 145-145: Unsafe construction of an any type value.

(@typescript-eslint/no-unsafe-call)


[error] 148-148: Unsafe member access .createPerf on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 148-148: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 149-149: Unsafe member access .simpleDB__updateAccountTokenList on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 157-157: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 157-157: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 158-158: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 159-159: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 159-159: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 161-161: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 161-161: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)

packages/kit-bg/src/services/ServiceToken.ts (2)

Line range hint 77-107: 建议添加参数说明文档

新增的 dbAccount 参数有助于减少数据库查询,提升性能。建议添加以下文档说明:

+ /**
+  * @param dbAccount 可选的数据库账户对象,用于避免重复查询
+  * @param accountId 账户ID
+  * @param networkId 网络ID
+  */

Also applies to: 475-504

🧰 Tools
🪛 eslint

[error] 75-75: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


Line range hint 527-600: 需要改进类型安全性

perfUtils 的使用存在类型安全问题,建议:

- const perf = perfUtils.createPerf(
+ const perf: IPerfUtils = perfUtils.createPerf(

同时确保 perfUtils 导出正确的类型定义。

🧰 Tools
🪛 eslint

[error] 551-551: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 551-551: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 554-554: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 554-554: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 566-566: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 566-566: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 2d3be6a and 90b98f6.

📒 Files selected for processing (2)
  • packages/kit-bg/src/dbs/simple/entity/SimpleDbEntityLocalTokens.ts (6 hunks)
  • packages/kit-bg/src/services/ServiceToken.ts (13 hunks)
🧰 Additional context used
🪛 eslint
packages/kit-bg/src/dbs/simple/entity/SimpleDbEntityLocalTokens.ts

[error] 148-148: Unsafe member access .createPerf on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 148-148: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 149-149: Unsafe member access .simpleDB__updateAccountTokenList on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 157-157: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 157-157: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 158-158: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 159-159: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 159-159: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 161-161: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 161-161: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 185-185: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 185-185: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 186-186: Unsafe member access .done on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 186-186: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 235-235: Unsafe construction of an any type value.

(@typescript-eslint/no-unsafe-call)


[error] 237-237: Unsafe member access .createPerf on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 237-237: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 238-238: Unsafe member access .simpleDB__getAccountTokenList on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 246-246: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 246-246: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 247-247: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 248-248: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 248-248: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 250-250: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 250-250: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 256-256: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 256-256: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 259-259: Computed name [key] resolves to an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 260-260: Computed name [key] resolves to an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 261-261: Computed name [key] resolves to an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 262-262: Computed name [key] resolves to an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 263-263: Computed name [key] resolves to an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 266-266: Unsafe member access .done on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 266-266: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)

packages/kit-bg/src/services/ServiceToken.ts

[error] 527-527: Unsafe member access .createPerf on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 527-527: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 528-528: Unsafe member access .allNetwork__getAccountLocalTokens on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 540-540: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 540-540: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 551-551: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 551-551: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 554-554: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 554-554: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 566-566: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 566-566: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 579-579: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 579-579: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 597-597: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 597-597: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 600-600: Unsafe member access .done on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 600-600: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)

🔇 Additional comments (2)
packages/kit-bg/src/services/ServiceToken.ts (2)

Line range hint 10-35: 性能监控工具集成完成!

引入 perfUtils 和相关类型定义的改动很合理,为性能监控提供了基础支持。


Line range hint 527-600: 性能监控点设置合理

性能监控覆盖了关键操作:

  • 账户信息获取
  • 代币列表获取
  • 数据映射转换

监控粒度适中,能够有效定位性能瓶颈。

🧰 Tools
🪛 eslint

[error] 551-551: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 551-551: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 554-554: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 554-554: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 566-566: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 566-566: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range comments (4)
packages/kit/src/views/Setting/pages/Notifications/ManageAccountActivity.tsx (3)

Line range hint 479-484: 建议改进 Promise 处理方式

当前使用 void 操作符处理 Promise 可能会忽略潜在的错误。建议添加错误处理逻辑。

 useEffect(
   () => () => {
-    void backgroundApiProxy.serviceNotification.registerClientWithOverrideAllAccounts();
+    backgroundApiProxy.serviceNotification
+      .registerClientWithOverrideAllAccounts()
+      .catch((error) => {
+        console.error('注册客户端失败:', error);
+      });
   },
   [],
 );
🧰 Tools
🪛 eslint

[error] 426-426: Unsafe member access .formatMessage on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 426-426: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 426-426: Unsafe member access .global_manage on an any value.

(@typescript-eslint/no-unsafe-member-access)


Line range hint 441-458: 建议优化性能

考虑使用 useMemo 来缓存 wallets 数组的渲染结果,特别是在处理大量钱包数据时,这可以避免不必要的重渲染。

+ const walletList = useMemo(() => (
+   wallets.map((wallet, index) => (
+     <YStack
+       key={wallet.id}
+       {...(index !== 0 && {
+         borderTopWidth: StyleSheet.hairlineWidth,
+         borderTopColor: '$borderSubdued',
+       })}
+     >
+       <AccordionItem
+         wallet={wallet}
+         onWalletEnabledChange={onWalletEnabledChange}
+       />
+       {wallet.hiddenWallets?.map((hiddenWallet) => (
+         <AccordionItem
+           key={hiddenWallet.id}
+           wallet={hiddenWallet}
+           onWalletEnabledChange={onWalletEnabledChange}
+         />
+       ))}
+     </YStack>
+   ))
+ ), [wallets, onWalletEnabledChange]);
🧰 Tools
🪛 eslint

[error] 426-426: Unsafe member access .formatMessage on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 426-426: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 426-426: Unsafe member access .global_manage on an any value.

(@typescript-eslint/no-unsafe-member-access)


Line range hint 82-91: 需要添加错误处理

异步操作缺少错误处理机制,这可能导致运行时错误无法被捕获和处理。

 useEffect(() => {
   void (async () => {
+    try {
       const savedSettings =
         await backgroundApiProxy.simpleDb.notificationSettings.getRawData();
       if (savedSettings) {
         setSettings(savedSettings.accountActivity);
       }
+    } catch (error) {
+      console.error('获取通知设置失败:', error);
+      // 考虑添加用户提示或降级处理
+    }
   })();
 }, []);
🧰 Tools
🪛 eslint

[error] 426-426: Unsafe member access .formatMessage on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 426-426: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 426-426: Unsafe member access .global_manage on an any value.

(@typescript-eslint/no-unsafe-member-access)

packages/kit-bg/src/services/ServiceToken.ts (1)

Line range hint 528-601: 需要改进类型安全性

性能监控实现需要解决类型安全问题:

- const perf = perfUtils.createPerf(
+ const perf: IPerfUtils = perfUtils.createPerf(
    EPerformanceTimerLogNames.allNetwork__getAccountLocalTokens,
  );

建议:

  1. 为 perfUtils 添加适当的类型定义
  2. 确保所有性能监控方法调用都有正确的类型标注
🧰 Tools
🪛 eslint

[error] 552-552: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 552-552: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 555-555: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 555-555: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 567-567: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 567-567: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 90b98f6 and 5a1d2f7.

📒 Files selected for processing (2)
  • packages/kit-bg/src/services/ServiceToken.ts (13 hunks)
  • packages/kit/src/views/Setting/pages/Notifications/ManageAccountActivity.tsx (1 hunks)
🧰 Additional context used
🪛 eslint
packages/kit-bg/src/services/ServiceToken.ts

[error] 528-528: Unsafe member access .createPerf on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 528-528: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 529-529: Unsafe member access .allNetwork__getAccountLocalTokens on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 541-541: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 541-541: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 552-552: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 552-552: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 555-555: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 555-555: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 567-567: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 567-567: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 580-580: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 580-580: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 598-598: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 598-598: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 601-601: Unsafe member access .done on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 601-601: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)

🔇 Additional comments (2)
packages/kit/src/views/Setting/pages/Notifications/ManageAccountActivity.tsx (1)

428-428: 滚动功能已正确启用!

为 Page 组件添加 scrollEnabled 属性是个好的改动,可以确保内容溢出时用户体验不受影响。

packages/kit-bg/src/services/ServiceToken.ts (1)

11-13: 性能监控工具导入和类型定义更新

导入性能监控工具和新增类型定义的改动合理,为后续的性能优化提供了基础。

Also applies to: 35-37

packages/kit-bg/src/services/ServiceToken.ts Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 5a1d2f7 and 7e299b2.

📒 Files selected for processing (1)
  • packages/kit/src/views/Home/pages/TokenListContainer.tsx (5 hunks)
🧰 Additional context used
🪛 eslint
packages/kit/src/views/Home/pages/TokenListContainer.tsx

[error] 358-358: Unsafe member access .serviceToken on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 358-358: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 589-589: Unsafe member access .createPerf on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 589-589: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 590-590: Unsafe member access .allNetwork__handleAllNetworkCacheRequests on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 593-593: Unsafe member access .markStart on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 593-593: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 599-599: Unsafe member access .serviceToken on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 599-599: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 606-606: Unsafe member access .markEnd on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 606-606: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)


[error] 610-610: Unsafe member access .done on an any value.

(@typescript-eslint/no-unsafe-member-access)


[error] 610-610: Unsafe call of an any typed value.

(@typescript-eslint/no-unsafe-call)

🔇 Additional comments (5)
packages/kit/src/views/Home/pages/TokenListContainer.tsx (5)

16-19: 引入新的类型定义以增强类型安全性。

导入IDBAccountIDBUtxoAccount类型,提高了代码的类型检查和可靠性。


350-355: 添加可选参数以增强函数灵活性。

新增dbAccountallNetworkDataInit可选参数,使函数更具扩展性,满足不同场景的需求。


359-359: 传递dbAccount参数以支持新的功能。

在调用fetchAccountTokens时增加dbAccount参数,确保新添加的可选参数被正确地使用。


581-587: 为函数添加新的可选参数simpleDbLocalTokensRawData

增加simpleDbLocalTokensRawData参数,允许函数在需要时接收本地令牌数据,提升性能和灵活性。


1290-1290: 删除注释的测试代码以保持代码整洁。

注释掉的<TokenListContainerPerfTest>组件可能已不再需要,建议删除以提高代码可读性。

@sidmorizon sidmorizon merged commit 996a6ca into x Nov 6, 2024
8 checks passed
@sidmorizon sidmorizon deleted the fix/db-perf-test branch November 6, 2024 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants