使用 onQueryStarted 处理程序导致 CPU 使用率过高

问题描述 投票:0回答:1

我正在使用 Redux-toolkit 学习 RTK 查询。从文档中阅读这篇文章: https://redux.js.org/tutorials/essentials/part-8-rtk-query-advanced#implementing-optimistic-updates 我从文档中写了完全相同的博客,但是 CPU 有一个大问题。

即使我不运行项目,但我的 IDE 只是打开,- 我的 CPU 使用率从一开始就加载了 80-90%。而 onQueryStarted 处理程序导致了这一点。因为当我注释掉这个处理程序时,-CPU 使用率立即加载了几个 %。

我尝试手动从文档中编写博客,但即使我从 redux 文档中复制粘贴整个 apiSlice,问题仍然是一样的。

所以我会给出这个切片表单文档的链接:

  1. https://codesandbox.io/s/github/reduxjs/redux-essentials-example-app/tree/checkpoint-6-rtkqConversion/?from-embed=&file=/src/features/api/apiSlice.js
  2. 这部分代码是我CPU占用率高的原因:
const patchResult = dispatch(
          apiSlice.util.updateQueryData('getPosts', undefined, (draft) => {
            // The `draft` is Immer-wrapped and can be "mutated" like in createSlice
            const post = draft.find((post) => post.id === postId)
            if (post) {
              post.reactions[reaction]++
            }
          })
        )

因为如果我将其注释掉,-一切都会立即变得正常。 我为 redux 开发人员创建了一个问题(附有简短视频以显示该问题): https://github.com/reduxjs/redux-toolkit/issues/3346

但是已经5天没有回音了。我想学习这个库,我喜欢它的概念和想法,但我就是学不会。

也许有人已经遇到过这类问题并且有一些经验。任何答案将不胜感激。提前致谢!

redux redux-toolkit rtk-query
1个回答
0
投票

问题是php storm IDE默认插件引起的。即使在我再次打开它之后,- 一切都很好。之前重新加载 IDE 没有帮助,但这个插件有帮助。代码运行良好,CPU 没有问题

© www.soinside.com 2019 - 2024. All rights reserved.