-
Notifications
You must be signed in to change notification settings - Fork 61
feat: add rating in card #372
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
base: dev
Are you sure you want to change the base?
Conversation
src/services/operation.ts
Outdated
}) | ||
wrapErrorMessage( | ||
(e) => `提交评分失败:${formatError(e)}`, | ||
mutate(async (val) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrapErrorMessage(
(e) => `提交评分失败:${formatError(e)}`,
mutate(
`rateOperation-${operationId}-${decision}`,
async (val) => {
await rateOperation({
id: operationId,
rating: decision,
})
return val
}),
).catch(console.warn)
for mutex of http requests.
@guansss , previously, multple like and dislike post operations were sent to the server.
In other words, I would doubt the validity of the data if they were sent from the browser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martinwang2002 mutate() 的 key 不是用来做 mutex 的吧,是用来与 useSWR() 里同样的 key 对应起来,以更新缓存并触发 revalidate
短时间发送多个请求是没问题的,反正最后都会 revalidate,以服务器返回的数据为准
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我试了一下,这请求确实太多了点……
edit: 原因是这个 mutate() 的第一个参数是 key,这里传了个发请求的函数进去作为 key,所以实际上是整个页面里有多少个 useSWR() 就发了多少个 rating 请求,并且刷新了所有的 useSWR()……
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我试了一下,这请求确实太多了点……
edit: 原因是这个 mutate() 的第一个参数是 key,这里传了个发请求的函数进去作为 key,所以实际上是整个页面里有多少个 useSWR() 就发了多少个 rating 请求,并且刷新了所有的 useSWR()……
一个函数作为key传入后,被当成了filter,这就导致了“整个页面里有多少个 useSWR() 就发了多少个 rating 请求”。
Also, another problem is that the state of the button requires refreshes, which requires the whole page of opeartions from the server side if my manual tests are undergoing correctly. |
是说点赞的操作会导致别的operation也会从服务器重新获取吗,我在 |
This is not caused by the update in rating, sorry for my misinterpretation. 这不是由于评分api产生的,不好意思x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把 useOperation()
放在 OperationCard
里的做法会导致大量的额外请求
mutate()
的使用方式有误,可以参考上面的解释
另外,代码看起来没有经过格式化,建议运行 yarn lint:check:eslint
或者在 IDE 里装个 eslint 插件来检查一下
感谢反馈!我来研究一下该怎么修改 |
@guansss 之前 |
现在 大量请求不仅仅是 |
啊,了解了,我再改改 |
将更新operation的逻辑移到了OperationList中,现在是纯前端表现了,没有同步后端的ratingType,这种表现能接受吗。 另外, |
带authorization: Bearer TOKEN 请求的会返回ratingType。 详见: ZOOT-Plus/ZootPlusBackend#179
可能需要后端确认一下query api是否支持带token访问,(毕竟有一些有cache) |
@martinwang2002 |
后端目前未处理列表页的点赞信息,ref: 列表查询逻辑 要支持该功能,后端需要在查询到数据后(不管是否为缓存中数据)都执行一次点赞信息查询。可以考虑先做上去观察一下会不会出现性能问题。 |
#328 相关
改动后ui表现如下:

如果有代码问题请告诉我,我对react并不熟悉