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

权限管理更新错误 #19

Open
mandomwu opened this issue Jul 23, 2017 · 0 comments
Open

权限管理更新错误 #19

mandomwu opened this issue Jul 23, 2017 · 0 comments

Comments

@mandomwu
Copy link

func (this *ManageGroupPermissionController) Post() {
在这个函数中, 在for循环中使用了SnowFlakeId来生成id
但实际使用过程中发现, 如果更新太快, 会导致snowFlakeid获取的id重复, 导致设置权限失败

看了一下snowFlakeid, 发现这个东西是根据当前毫秒级时间戳+线程id+序号
由于每次都生成新的序号, 导致在同已毫秒内获取到的id都是一样的,建议对Util的SnowFlakeId进行修改

由于没有时间测试, 所以我简单处理了一下,目前我的解决方案是
iw, _ := goSnowFlake.NewIdWorker(1)
for _, v := range names {
pid, _ := strconv.Atoi(v)
id, err := iw.NextId()
if err != nil {
id, _ = iw.NextId()
}
groupPermission.Id = id
groupPermission.Permissionid = int64(pid)
err = AddGroupsPermission(groupPermission)
}

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

No branches or pull requests

1 participant