Skip to content

Conversation

ityifan
Copy link
Collaborator

@ityifan ityifan commented Sep 17, 2025

No description provided.

@ityifan ityifan changed the title 修改为删除缓存滞后执行 修复事务同步执行删除缓存问题 Sep 19, 2025
return result
})

if (clearCacheNsps.length > 0) { await this.cache.mDelete(clearCacheNsps) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

考虑下这句话能不能放到上面18行的位置,是否有必要在事务外面执行


async getById(id: string, pick = this.columns, trx?: CoaMysql.Transaction, ms = this.ms, force = false) {
const result = await this.redisCache.warp(this.getCacheNsp('id'), id, async () => await super.getById(id, this.columns, trx), ms, force)
const result = trx ? await super.getById(id, this.columns, trx) : await this.redisCache.warp(this.getCacheNsp('id'), id, async () => await super.getById(id, this.columns, trx), ms, force)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有问题:
1、直接判断是不是 trx 太简单了,一改所有的代码都有影响,我们新加一个 safeTransaction 的目的就是平滑迁移,自由 safeTransaction 的方法才会使用新的逻辑,下面有几个都是一样,都需要改
2、还有一个这个场景的问题需要考量,等你改完再讨论


protected async deleteCache(ids: string[], dataList: Array<CoaMysql.SafePartial<Scheme>>) {
async deleteCache(ids: string[], dataList: Array<CoaMysql.SafePartial<Scheme>>, trx?: CoaMysql.Transaction) {
if (trx && !(trx as any).clearCacheNsps) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上面,这些逻辑的判断都有问题

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

Successfully merging this pull request may close these issues.

2 participants