正在显示
1 个修改的文件
包含
9 行增加
和
2 行删除
| @@ -216,6 +216,7 @@ func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn | @@ -216,6 +216,7 @@ func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn | ||
| 216 | queryFunc := func() (interface{}, error) { | 216 | queryFunc := func() (interface{}, error) { |
| 217 | tx = tx.Model(m).Updates(map[string]interface{}{ | 217 | tx = tx.Model(m).Updates(map[string]interface{}{ |
| 218 | "count_love": gorm.Expr("count_love+?", incr), | 218 | "count_love": gorm.Expr("count_love+?", incr), |
| 219 | + "version": gorm.Expr("version+1"), | ||
| 219 | }) | 220 | }) |
| 220 | return nil, tx.Error | 221 | return nil, tx.Error |
| 221 | } | 222 | } |
| @@ -236,7 +237,10 @@ func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn | @@ -236,7 +237,10 @@ func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn | ||
| 236 | return err | 237 | return err |
| 237 | } | 238 | } |
| 238 | queryFunc := func() (interface{}, error) { | 239 | queryFunc := func() (interface{}, error) { |
| 239 | - tx = tx.Model(m).Update("count_read", gorm.Expr("count_read+?", incr)) | 240 | + tx = tx.Model(m).Updates(map[string]interface{}{ |
| 241 | + "version": gorm.Expr("version+1"), | ||
| 242 | + "count_read": gorm.Expr("count_read+?", incr), | ||
| 243 | + }) | ||
| 240 | return nil, tx.Error | 244 | return nil, tx.Error |
| 241 | } | 245 | } |
| 242 | if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | 246 | if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { |
| @@ -256,7 +260,10 @@ func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, c | @@ -256,7 +260,10 @@ func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, c | ||
| 256 | return err | 260 | return err |
| 257 | } | 261 | } |
| 258 | queryFunc := func() (interface{}, error) { | 262 | queryFunc := func() (interface{}, error) { |
| 259 | - tx = tx.Model(m).Update("count_comment", gorm.Expr("count_comment+?", incr)) | 263 | + tx = tx.Model(m).Updates(map[string]interface{}{ |
| 264 | + "version": gorm.Expr("version+1"), | ||
| 265 | + "count_comment": gorm.Expr("count_comment+?", incr), | ||
| 266 | + }) | ||
| 260 | return nil, tx.Error | 267 | return nil, tx.Error |
| 261 | } | 268 | } |
| 262 | if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | 269 | if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { |
-
请 注册 或 登录 后发表评论