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

点赞功能开发时遇到的时差问题 #26

Open
Tomotoes opened this issue Feb 17, 2020 · 0 comments
Open

点赞功能开发时遇到的时差问题 #26

Tomotoes opened this issue Feb 17, 2020 · 0 comments

Comments

@Tomotoes
Copy link
Owner

Tomotoes commented Feb 17, 2020

在开发微博点赞的过程中,本以为将所有的数据都存在一个字段里,减少请求数量,可我忽视了一个重要的问题,数据的同步。
假如你在某一时刻(A)打开微博,过了一段时间(B)后,点了个赞。
那么在 B 后,微博的最终数据,就是 A 之前的数据加上你这一个赞。
在 B 的过程中,所有其他游客的数据都会被你这一个赞抹掉。

解决方法也很简单:每次点赞前,重新拉取数据,可是这样 还会有些许时差冲突。

栗子: 我是时间线呐
A 点赞: A 拉取数据, 数据内存变化, 保存数据
B 点赞: ======= B 拉取数据, 数据内存变化, 保存数据.

呃,A 的点赞数据丢了。

看来,想达到数据不丢失,还是要换回最开始的数据模型。

即:数据表中的每一行代表一条微博,里面设置time字段,然后通过 increment 更新。

代价就是慢了。

为什么 Leancloud 不能提供一个批量查询数据的 API,本以为用上 他家的SDK 后,会优化请求方式,但现在看来,就是一个 简易的 ORM...

不好玩。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant