zeromicro / zeromicro/zero-doc

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

Open
#59 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
600
Forks
249
PR merge metrics
No merged PRs in 30d

Description

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

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

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

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the goctl-generated Update method and its template, then trace how the id and unique-index fields are used to build Redis cache keys. Reproduce an update that changes a unique index and verify that the old key is removed while the new key and primary-key cache remain valid.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, redis
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.