High CPU usage by using onQueryStarted handler

huangapple go评论56阅读模式
英文:

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:

  1. https://codesandbox.io/s/github/reduxjs/redux-essentials-example-app/tree/checkpoint-6-rtkqConversion/?from-embed=&file=/src/features/api/apiSlice.js

  2. 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:

  1. https://codesandbox.io/s/github/reduxjs/redux-essentials-example-app/tree/checkpoint-6-rtkqConversion/?from-embed=&file=/src/features/api/apiSlice.js
  2. 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没有问题。

英文:

The problem was caused by default plugin in php storm IDE. Even after I turned it ON again, - everything is fine. Reloading IDE before didn't help, but this plugin does. Code works fine, no problems with CPU
High CPU usage by using onQueryStarted handler

huangapple
  • 本文由 发表于 2023年4月17日 22:59:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76036540.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定