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

关于go-ctl模版更新方法的缺陷 #59

Open
chenjianjun571 opened this issue Sep 15, 2021 · 0 comments
Open

关于go-ctl模版更新方法的缺陷 #59

chenjianjun571 opened this issue Sep 15, 2021 · 0 comments

Comments

@chenjianjun571
Copy link

chenjianjun571 commented Sep 15, 2021

如果一个表有唯一索引,目前的goctl模版是有缺陷的

自动生成的Update方法是基于传入的data字段进行缓存key组合并删除。如果使用者修改的是唯一索引字段,会导致修改前的唯一索引缓存key不会被删除。
比如:
用户表 user 主键key是id,唯一索引是phone
数据库存在一条记录id:3 phone1:123456 对应的redis缓存是 user:id:3-----指向>>>>数据 user:phone1:123456-------指向>>>>3
使用放把id为3的电话号码修改为654321,那么按照目前的方式,缓存里面会出现这样的情况:
user:id:3-----指向>>>>数据
user:phone1:123456-------指向>>>>3 (未删除)
user:phone1:654321-------指向>>>>3(修改后访问新增)

解决办法
在update的时候,通过id取一下旧值,然后通过旧值把缓存key删除

我的实现方案,官方可以考虑
image

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