英文:
High CPU usage by using onQueryStarted handler
问题
I'm learning RTK query with Redux-toolkit. Reading this article from docs: https://redux.js.org/tutorials/essentials/part-8-rtk-query-advanced#implementing-optimistic-updates I wrote exactly the same blog from documentation, but got a big issue with CPU.
Even if I don't run the project, but my IDE is just open,- my CPU usage is loaded by 80-90% from the beginning. And onQueryStarted handler causes this. Because when I comment this handler out, - CPU usage immediately gets loaded by a few %.
I tried to write a blog from documentation by hand, but even if I do copy-paste the entire apiSlice from redux documentation, - the problem is still the same.
So I will give a link to this slice form docs:
-
This part of the code is the reason for my high CPU usage:
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]++ } }) )
Because if I comment this out, - everything becomes OK immediately. I created an issue for redux developers (with a short video attached to show the issue): https://github.com/reduxjs/redux-toolkit/issues/3346
But 5 days already passed without an answer. I want to learn this library, I like the concepts and idea, but I simply can't.
Maybe somebody already got this sort of problem and has some experience. Any answer will be appreciated. Thanks in advance!
英文:
I'm learning RTK query with Redux-toolkit. Reading this article from docs:
https://redux.js.org/tutorials/essentials/part-8-rtk-query-advanced#implementing-optimistic-updates
I wrote exactly the same blog from documentation, but got a big issue with CPU.
Even if I don't run the project, but my IDE is just open,- my CPU usage is loaded by 80-90% from the beginning. And onQueryStarted handler causes this. Because when I comment this handler out, - CPU usage immediately gets loaded by few %.
I tried to write blog from documentation by hands, but even If I do copy-paste entire apiSlice from redux documentation, - the problem is still the same.
So I will give a link to this slice form docs:
- https://codesandbox.io/s/github/reduxjs/redux-essentials-example-app/tree/checkpoint-6-rtkqConversion/?from-embed=&file=/src/features/api/apiSlice.js
- This part of code is the reason of my high CPU usage:
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]++
}
})
)
Because if I comment this out, - everything becomes OK immidiately.
I created an issue for redux developers (with short video attached to show the issue):
https://github.com/reduxjs/redux-toolkit/issues/3346
But 5 days already passed without answer. I want to learn this library, I like the concepts and idea, but I simply can't.
Maybe somebody already got this sort of problem and have some experience. Any answer will be appreciated. Thanks in advance!
答案1
得分: 0
问题是由php storm IDE中的默认插件引起的。即使我再次打开它,一切都正常。之前重新加载IDE没有帮助,但这个插件有用。代码正常运行,CPU没有问题。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论